How to handle nulls in linq to entities -


how handle null max value in linq entities statement?

int userlevelid = db.characters.where(o => o.userid == userid).max(o => o.levelid); 

i'm not quite sure mean when count, since aren't referring count anywhere in code. if wonding how handle null o.levelid this:

max(o => o.levelid ?? -1); 

?? coalesce operator in .net

update

try this:

db.characters.where(o => o.userid == userid).max(o => o == null ? 0 : o.levelid); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -