简体   繁体   中英

Entity Framwork Core + Linq: How do I get the entire entity that has the max value? Looking for a more elegant solution

This is what I have so far:

var TEST = await context.ProcessRevision.FirstOrDefaultAsync(i => i.ProcessRevId == (context.ProcessRevision.Max(i => i.ProcessRevId)));

I am unsure whether this is a good solution or if I could do something a little more elegant with less processing.

Any suggestions?

Just sort it in descending order and get the first entity. Most likely this is EF context? So it should be translated into a select top (1) with order by ... desc .

var test = await context.ProcessRevision.OrderByDescending(r => r.ProcessRevId).FirstOrDefaultAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM