开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜