How to compare only date components from DateTime in EF?

后端 未结 14 1009
野性不改
野性不改 2020-11-27 17:06

I am having two date values, one already stored in the database and the other selected by the user using DatePicker. The use case is to search for a particular date from the

14条回答
  •  春和景丽
    2020-11-27 17:37

    Just always compare the Date property of DateTime, instead of the full date time.

    When you make your LINQ query, use date.Date in the query, ie:

    var results = from c in collection
                  where c.Date == myDateTime.Date
                  select c;
    

提交回复
热议问题