嗨,我在实体框架中有查询,但是它不起作用。你有什么想法吗?
我需要这个结果
SELECT id, min(price) minPrice
FROM (
SELECT id, max(servicePrice) msi FROM offers
GROUP BY id
) as mvo INNER JOIN offers so ON mvo.id=so.id AND mvo.msi=so.servicePrice
WHERE so.id=o.id
GROUP BY so.id
我尝试了以下代码,但是有两个错误。 Join返回The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
。没有minPrice = ms.Min(s => s.price)
时,最后一次选择可以正常工作。当我有min函数时,运行时将返回System.ArgumentException: 'Value does not fall within the expected range.'
var q =
from vo in dataContext.Offers join so in (
from o in dataContext.Offers
group o by o.id into oo
select new { id = oo.Key, MaxSI = oo.Max(v => (v.servicePrice)) }
) on new { vo.id, vo.servicePrice } equals new { so.id, so.MaxSI }
group vo by vo.id into ms
select new { id = ms.Key, minPrice = ms.Min(s => s.price) }
;
答案 0 :(得分:0)
我认为加入应该像这样-
var q =
from vo in dataContext.Offers join so in (
from o in dataContext.Offers
group o by o.id into oo
select new { id = oo.Key, MaxSI = oo.Max(v => (v.servicePrice)) }
)
on new { id = vo.id, price = vo.servicePrice } equals new { id = so.id, price = so.MaxSI }
group vo by vo.id into ms
select new { id = ms.Key, minPrice = ms.Min(s => s.price) }
;