Sunday, August 20, 2023

How do I get the max ID with Linq to Entity?

 Do that like this

db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();

No comments:

Post a Comment

Get max value for identity column without a table scan

  You can use   IDENT_CURRENT   to look up the last identity value to be inserted, e.g. IDENT_CURRENT( 'MyTable' ) However, be caut...