How do I perform Date Comparison in EF query?

后端 未结 11 1286
悲哀的现实
悲哀的现实 2020-11-30 07:33

Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query.

Example: If I wanted all Employee names for those who started befo

11条回答
  •  醉梦人生
    2020-11-30 07:44

    You can not use .Date

    If you would like to check for today you can create a datetime with no time

    DateTime myDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
    var e = (from mds in myEntities.Table
             where mds.CreateDateTime >= myDate
             select mds).FirstOrDefault();
    

提交回复
热议问题