我在使用NHibernate、LINQ to NHibernate和C#时,无法在单个表格上执行多个计数的LINQ查询。
查询是一个已填充的列表。我有一个包含布尔值FullRef的表格。我想要执行一个LINQ查询,以便计算每个TrackId中FullRef = false和FullRef = true的出现次数。每当TrackId获取track.Source == "UserRef"时,TrackId都会获得一个新行。
在下面的查询中,我可以正确地计算FullRefTrueCount中FullRef = true的数量,但它在FullRefFalseCount中给出了未知的错误数字。
var query2 = from track in query
where track.Source == "UserRef"
group track by new { TrackId = track.TrackId, FullRef = track.FullRef } into d
select new FullReferrer
{
Customer = d.Key.TrackId,
FullRefFalseCount = d.Where(x => x.FullRef == false).Count(),
FullRefTrueCount = d.Where(x => x.FullRef == true).Count()
};
有人知道如何解决这个问题吗?我相当确定.Where()子句被忽略了,而" group by"正让我感到困扰。 如果我可以以某种方式
group track by new { TrackId = track.TrackId, FullRefTrue = track.FullRef, FullRefFalse = !track.FullRef }"
它会起作用。有没有什么办法做到这一点?