c# - FirstOrDefault inline null checking -


i have following code :

var result = new collection<object>();  result.add(      list.select(s => new      {           s.name,           rating = s.performance.orderbydescending(o => o.year).firstordefault().rating      }) ); 

if there's no record found in performance, give me nullexception expected because i'm trying rating property null value question how set null if firstordefault() null , rating value if not.

thanks

do this:

rating = s.performance.orderbydescending(o => o.year)                       .select(o => o.rating)                       .firstordefault() 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -