我已经写了一些LINQ来模拟SQL GroupBy语句(见下文)。然而,在我的group by之前,我也只需要考虑最后10个settingIds。我想我会使用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()
};发布于 2012-04-12 15:09:42
我会做这样的事情
var settings2 = from sOuter in
(from s in dc.SystemSettings
where s.campConfig.campaignType == campType
&& s.campId != campId
&& s.settingKey == ticket.setting.Key
orderby s.settingId descending
select s).Take(10)
group sOuter by sOuter.settingValue
into grp
select new
{
SettingValue = grp.Key,
SettingCount = grp.Select(x => x.settingValue).Count()
};https://stackoverflow.com/questions/10118605
复制相似问题