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

后端 未结 2 1217
一生所求
一生所求 2021-01-19 03:50

I have this method that is supposed to get the latest messages posted, from the Table (& EntitySet) called ENTRY

///method gets \"days\" as parameter, used in ne

相关标签:
2条回答
  • 2021-01-19 04:06

    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 > ...
    
    0 讨论(0)
  • 2021-01-19 04:07

    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.

    0 讨论(0)
提交回复
热议问题