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();
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论