我有以下SQL查询...
select seaMake AS Make,
seaModel AS Model,
COUNT(*) AS [Count],
MIN(seaPrice) AS [From],
MIN(seaCapId) AS [CapId]
from tblSearch
where seaPrice >= 2000
and seaPrice <= 7000
group by seaMake, seaModel
order by seaMake, seaModel
我试图将其编写为LINQ to Entities Query,但遇到问题。到目前为止,这是我所拥有的,但是我无法从var S中访问品牌和型号值
var tester = from s in db.tblSearches
where s.seaPrice >= 2000
&& s.seaPrice <= 7000
orderby s.seaMake
group s by s.seaMake into g
select new
{
make = g.seaMake,
model = s.seaModel,
count = g.Max(x => x.seaMake),
PriceFrom = g.Min(s.seaPrice)
};
我要去哪里错了?
最佳答案
这应该是SQL的简单翻译:
from s in db.tblSearches
where
s.seaPrice >= 2000 &&
s.seaPrice <= 7000
group s by new {s.seaMake, s.seaModel} into g
orderby g.Key
select new
{
Make = g.Key.seaMake,
Model = g.Key.seaModel,
Count = g.Count(),
From = g.Min(x => x.seaPrice),
CapId = g.Min(x => x.seaCapId)
}
关于c# - 带有聚集和分组依据的LINQ查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12941794/