我编写了一些 LINQ 来模拟 SQL GroupBy 语句(见下文)。但是,在分组之前,我也只需要考虑最后 10 个 settingId。我想我会使用 Take 来执行此操作,但是我的语句中正确的语法是什么?
var settings2 = from s in dc.SystemSettings
where s.campConfig.campaignType == campType
&& s.campId != campId
&& s.settingKey == ticket.setting.Key
orderby s.settingId descending
group s by s.settingValue
into grp
select new
{
SettingValue = grp.Key,
SettingCount = grp.Select(x => x.settingValue).Count()
};