I have to find an object in an EF4 entity collection with a specific ID
property and return the int value if it's found and return  (int?)null if
otherwise. This skeleton code crashes of course if the ID isn't found.

 

int? foundId = context.Things.SingleOrDefault(t => t.ID == lookupID).ID;

 

So what is the best way of recoding this elegantly as a one-liner so it
gives me the ID or null when not found? It has to be a one-liner because
it's in a select clause.

 

Greg

Reply via email to