var lastitem = Contacts
.OrderByDescending(c => c.ContactID)
.Take(1).Select(p=>p.ContactID);
lastitem
is even though a single item returns a DBQuery<Int32>
is there a way to convert it to just a pure Int32
?
Thanks for the help!
A开发者_如何学编程LSO:
is there a better way to do this? Basically, I'm trying to get an Int32
type from ContactID from the very last item inside the database
You want .First()
(throws if empty) or .FirstOrDefault()
(returns 0
if empty, or null if you add .Cast<int?()
first):
int lastitem = Contacts.OrderByDescending(c => c.ContactID)
.Select(c => c.ContactID)
.First();
精彩评论