日期:2014-05-20 浏览次数:20879 次
var query=from a in A join b in B on A.a_id equals b.a_id where a.a_isdel==0 && b.b_isdel==0 group b by b.a_id into g select new { a_id=g.Key, a_name=A.SingleOrDefault(c=>c.a_id==g.Key).a_name, b_name=g.OrderBy(c=>c.b_id).FirstOrDefault().b_name }; //代码手写 谨提供思路参考
------解决方案--------------------
猫哥写的很好啊
------解决方案--------------------
var result = from u in db.TableA
from n in db.TableB
where u.a_id == n.a_id && u.a_isdel == 0 && n.b_isdel == 0
group n by n.a_id into g
select new
{
a_id = g.Key,
a_name = db.TableA.SingleOrDefault(c => c.a_id == g.Key).a_name,
b_name =g.FirstOrDefault(c=>c.b_id==(g.Min(t=>t.b_id))).b_name
};
------解决方案--------------------