EF外连接 表达树
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var s = new [] {
new {id=1 , name =2}, new {id=2, name =2},new {id=4, name =4}
};
var d = new[] {
new {id=1 , make =2}, new {id=3, make =2}
};
var b = new[] {
new {id=1 , code =2}, new {id=3, code =3},new {id=4, code =4}
};
var q = from s1 in s
from b1 in b
where s1.id == b1.id
join d1 in d on s1.id equals d1.make where d1.id > 0
into sbs
from qq in sbs.DefaultIfEmpty()
select new
{
id = s1.id
num = qq == null ? "": (string)qq.make
};
/*
*/
/*
var q = from s1 in s
from d1 in d
where s1.id == d1.id
select new
{
id = s1.id,
make =d1.make
};
var q = from s1 in s
join d1 in d on s1.id equals d1.id
into ss
from p in ss.DefaultIfEmpty()
select new
{
id=s1.id,
make= p == null ? 0 : p.make
};
*/
foreach (var r in q)
{
Console.WriteLine(r.id);
Console.WriteLine(r.make);
Console.WriteLine("-------------");
}
/*
ParameterExpression c = Expression.Parameter(typeof(aproduct), "aproduct");
Expression condition = Expression.Constant(true);
Expression con = Expression.Call(Expression.Property(c, typeof(aproduct).GetProperty("ProductId")),
typeof(int).GetMethod("Equals", new Type[] { typeof(int) }),
Expression.Constant(1));
condition = Expression.And(con, condition);
Expression<Func<aproduct,bool>> end = Expression.Lambda<Func<aproduct,bool>>(condition,new ParameterExpression
[]{c});
var db = new skyEntities();
var q = db.aproduct.Where(end);
foreach(var s in q)
{
Console.WriteLine(s.ProductId);
}
*/
}
}
}