LINQ分组后取COUNT值再附加条件判断 急 高手进
from c in DataContext.album
join d in DataContext.photo
on c.aid equals d.albumid into p
from d in p.DefaultIfEmpty()
orderby c.entertime
descending
where c.userid == id && c.flag == false
group c by new { c.aid, c.title, c.photocover, c.userid } into g
select new {
g.Key.aid, //相册ID
g.Key.title, //标题
g.Key.photocover, //相册封面
g.Key.userid, //用户ID
count = g.Count(o=>o.photo!=null)
}
这个问题上次解决了,可以正常查出一个用户有多少相册,每个相册下相片数是多少。但是现在我需要加上photo表(相片)的flag为false的判断(flag为false表示相片没有被删除,flag为true表示被删除),上面的代码在某个相册下相片为0时,实际上有5个照片,但是flag都被置为了true,应该只能查出个数为0,但是实际上返回的是5,请问我如何让其显示为0?