Reputation: 157
I have this situation:
select max(id) from OTX group by AccNo
I want to convert it into a LINQ query but is not working. I tried this but says that Message = "The member 'XX' has no supported translation to SQL.":
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select Client.Max().ID;
Upvotes: 1
Views: 78
Reputation: 142038
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select new { MaxId = Client.Max(s => s.ID)};
Upvotes: 0
Reputation: 16067
Try
var result = from otx in datacTx.OTX
group otxCf by otxCf.AccNo
into Client
select Client.Max(r=>r.id);
or if you want the same as
select AccNo, max(id) from OTX group by AccNo
then try
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) } ;
Upvotes: 2