'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

后端 未结 8 551
粉色の甜心
粉色の甜心 2020-11-27 05:57

I am trying to execute the following code and am receiving an error

public List GetLoggingData(DateTime LogDate, string title)
{
     var context          


        
8条回答
  •  日久生厌
    2020-11-27 06:19

    If you are using EF 6.0+, you can use DbFunctions.TruncateTime(DateTime?) :

    var query =
        from t in context.Logs
        where t.Title == title 
        && DbFunctions.TruncateTime(t.Timestamp) == LogDate.Date
        select t;
    

    Note: For earlier version of EF where DbFunctions isn't available, EntityFunctions.TruncateTime(DateTime?) can be used instead.

提交回复
热议问题