【发布时间】:2011-04-30 09:02:12
【问题描述】:
我有以下 linq 表达式,可让我加入两个表,按 DSCID 对它们进行分组,然后获取分组值的计数:
var qryGeoApppendCount =
from a in append
join g in geo
on a.Field<string>("RNO")
equals g.Field<string>("RNO")
group g by g.Field<int>("DSCID") into appendGeo
select new
{
DscId = appendGeo.Key,
DscIdCount = appendGeo.Count()
};
我需要更进一步,只选择大于 1 的计数。我尝试过这样的事情:
select new
{
DscId = appendGeo.Key,
DscIdCount = appendGeo.Count(n => n.Count > 1)
};
但这没有用。我需要能够在qryGeoAppendQuery 返回计数 > 1 的记录时抛出错误,因此理想情况下,查询将包含在 if 语句中。
【问题讨论】:
标签: c# linq count conditional linq-group