mikemurf22 mikemurf22 - 25 days ago 6
C# Question

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

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

public List<Log> GetLoggingData(DateTime LogDate, string title)
{
var context = new LoggingEntities();
var query = from t in context.Logs

where t.Title == title
&& t.Timestamp == LogDate

select t;
return query.ToList();
}


The error I'm receiving is "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported." I have tried various attempts of casting everythign to a string, only comparing the date part, but can't seem to get the right combinaation. Any help is greatly appreciated.

Answer

Not the greatest solution, but it works. For a variety of reasons, I have to use .net 3.5 at this point and modifying the database would be difficult. Anyways, here is a solution that works:

            var query = from t in context.Logs
                      where t.Title == title 
                      && t.Timestamp.Day == LogDate.Day
                      && t.Timestamp.Month == LogDate.Month
                      && t.Timestamp.Year == LogDate.Year
                      select t;

Not the most elegant solution, but it is effective.