Good way to catch nulls from Entity-Framework?
Right now I'm doing this, but I don't like it very much:
decimal maxId = 0d;
try
{
maxId = ent.SaveStates.Max(c => c.Id);
}
catch (Exception ex) //no ent开发者_如何学运维ries in the db
{
maxId = 1;
}
Is there a better way to handle nulls from the DB with entity-framework?
Here's this:
maxId = ent.SaveStates.Count() > 0 ? ent.SaveStates.Max(c => c.Id) : null;
I don't think that will cause two queries, but I'd profile it to make sure.
精彩评论