The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties

后端 未结 10 2121
再見小時候
再見小時候 2020-11-28 02:47

Using this code in Entity Framework I receive the following error. I need to get all the rows for a specific date, DateTimeStart is of type Dat

10条回答
  •  感动是毒
    2020-11-28 03:16

    I have the same issue with Entity Framework 6.1.3

    But with different scenario. My model property is of type nullable DateTime

    DateTime? CreatedDate { get; set; }
    

    So I need to query on today's date to check all the record, so this what works for me. Which means I need to truncate both records to get the proper query on DbContext:

    Where(w => DbFunctions.TruncateTime(w.CreatedDate) == DbFunctions.TruncateTime(DateTime.Now);
    

提交回复
热议问题