LINQ 2 Entities , howto check DateTime.HasValue within the linq query

旧城冷巷雨未停 提交于 2019-12-01 20:47:54

What do you want to do in case DATECREATED is null?

If you just want to ignore these records use an additional condition(or where clause):

var entries = from ent in db.ENTRY
              where ent.DATECREATED.HasValue && ent.DATECREATED.Value > ...

Well... you can exclude entries with DATECREATED equal to null by simply using

entries = from ent in db.ENTRY 
          where ent.DATECREATED != null
          where ent.DATECREATE.Value > DateTime.Today....

and include them with

  entries = from ent in db.ENTRY 
          where ent.DATECREATED == null ||
                ent.DATECREATE.Value > DateTime.Today.....

I am not sure though if the second query actually stops checking the where clauses once the first condition is true.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!