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

<p>I've tried:</p>

<pre><code>using (MyDBEntities db = new MyDBEntities())
{
    var User = db.Users.Last();
    // or
    var User = db.Users.Max();

    return user.UserID;
}
</code></pre>

<p>but <code>Last</code> and <code>Max</code> don't seem to be supported.</p>

<p>Any ideas?</p>

Do that like this
```
```
db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
```
```