现在我正在做这件事,但我不是很喜欢:
decimal maxId = 0d;
try
{
maxId = ent.SaveStates.Max(c => c.Id);
}
catch (Exception ex) //no entries in the db
{
maxId = 1;
}有没有更好的方法来处理来自实体框架的数据库中的空值?
发布于 2011-01-12 03:01:26
下面是:
maxId = ent.SaveStates.Count() > 0 ? ent.SaveStates.Max(c => c.Id) : null;我不认为这会导致两个查询,但我会分析它以确保。
https://stackoverflow.com/questions/4661259
复制相似问题