读书人

Linq分组有关问题

发布时间: 2012-12-16 12:02:32 作者: rapoo

Linq分组问题,求救啊~
var mul = (from a in db.Bus_PowerTree
join b in db.Bus_Popedom
on a.Code equals b.Code
into joinTable
where a.Id > 0
//from b in joinTable.DefaultIfEmpty()
group a by a.ParentId //这里老是错,我不知道到底少了什么~
select new Bizlink.Models.Dayshouse.Message.PowerCommentsInfo()
{Id = a.Id,Name = a.Name,ParentId = a.ParentId });

model.ItemList = mul.ToList();
[最优解释]
你要按照LINQ的语法来写才行:

var mul = (from a in db.Bus_PowerTree
where a.Id > 0
join b in db.Bus_Popedom
on a.Code equals b.Code
into joinTable
from b in joinTable.DefaultIfEmpty()
group a by a.ParentId into g
select new Bizlink.Models.Dayshouse.Message.PowerCommentsInfo()
{Id = g.First().Id,Name = g.First().Name,ParentId = g.Key });

[其他解释]
从你的查询语句来看,最后的查询结果和db.Bus_Popedom 根本就没有关系啊
更别说用什么LEFT JOIN语句了


[其他解释]
group a by a.ParentId into groupname
select groupname.Key, groupname.First().xxx ...
[其他解释]
其实我一直很好奇~为啥搞出LINQ,我觉得反而麻烦了,是不是因为我不会用,所以觉得很麻烦~比普通的Sql语句比起来,难受死~
[其他解释]
你还没发现LINQ的魅力~
[其他解释]
楼上,我想学~
[其他解释]
那你干嘛用linq呢。

读书人网 >.NET

热点推荐