dpv
dpv

Reputation: 157

Convert SQL query to LINQ query not working

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

Answers (2)

Guru Stron
Guru Stron

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

sgmoore
sgmoore

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

Related Questions