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

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -