我遇到这种情况:
select max(id) from OTX group by AccNo
我想将其转换为LINQ查询但不起作用。我试过这个但是说Message =“成员'XX'没有支持的SQL翻译。”:
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select Client.Max().ID;
答案 0 :(得分:2)
尝试
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select Client.Max(r=>r.id);
或者如果你想和
一样select AccNo, max(id) from OTX group by AccNo
然后尝试
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select new { AccNo = Client.Key , MaxValue= Client.Max(r=>r.id) } ;
答案 1 :(得分:0)
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select new { MaxId = Client.Max(s => s.ID)};