我有一个匿名的Linq查询,它会为报告带回数据。我想知道是否可以计算此查询中出现多少个唯一PaperTestId
的计数,并在此查询中执行此操作。
var q = from p in dbcontext.table1
join d in dbcontext.table2 on p.DimId equals d.DimId
join dr in dbcontext.table3 on new { p.DimId, p.PaperTest.TestId } equals new { dr.DimId, dr.TestId }
join u in dbcontext.table4 on p.PaperTestId equals u.PaperTestId
where u.Completed >= endDate
&& u.paperTemplate.paperTitle == "Template"
&& u.paperTemplate.ProductionProgress >= 100m
orderby dr.DimScore
select new
{
Company = u.User.companyTitle,
Template = u.PapereName,
TestName = u.TestName,
TemplateType = u.paperTemplate.TemplateType,
DimId = p.Dimension.DimID,
Payment = p.Payment,
ScorePct = p.ScorePct,
TestIdCount = p.PaperTestId.Count() = // Get count here
};
我可以使用下面的代码获取查询之外的计数。
int testCount = q.Select(p => p.PaperTestId).Distinct().Count();