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

I have a table User which has an identity column UserID, now what is the correct Linq to Entity line of code that would return me the max UserID?

I've tried

        using (MyDBEntities db = new MyDBEntities())
            var User = db.Users.Last();
            // or
            var User = db.Users.Max();

            return user.UserID;

but Last and Max don't seem to be supported.

Any ideas?

Thank you,



Try with

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

Need Your Help

Can I lazy-load my libraries so they don't delay my app startup?

iphone performance startup

My app takes a long period of time during the startup, while the splash screen is shown. I assume that It is so due to the size of what the iOS has to load, including libraries. My question is, can I

PHP an MySQL - Fatal error: Function name must be a string

php mysql

I'm trying to show a value from a database table through PHP echo. The MySQL result is a double (10, 2).