在linq中使用left join时,同时count,应该怎么做?谢谢。
from q in OneSet
join x in OneSet
on q.id equals x.ParentID into temp
from qx in temp.DefaultIfEmpty()
{
//Count = ...
}
现在要查出x的Count的值,怎么做啊?谢谢。
------解决方案--------------------from q in OneSet
join x in OneSet
on q.id equals x.ParentID into temp
from qx in temp.DefaultIfEmpty()
select new
{
Count = qx==null?0:temp.Count()
}
------解决方案--------------------var q =
from a in OneSet
join b in TwoSet on a.ID equals b.ParentID
group a by new {AID=a.ID, AParentID=a.ParentID, AName=a.Name,AFlagStatus=a.flagStatus} into g
select new {g.Key, BCount=g.Count()};
foreach (var item in q)
{
//A记录信息:
item.Key.AID
item.Key.AParentID
item.Key.AName
item.Key.AFlagStatus
//对应B记录的数量:
item.BCount
}
------解决方案--------------------
var query=from q in OneSet
join x in TwoSet
on q.id equals x.ParentID
group q by new {AID=q.ID, AParentID=q.ParentID, AName=q.Name,AFlagStatus=q.flagStatus} into temp
select new
{
Key=temp.key,
Count=temp.Count()
}