I am getting an error: The specified type member 'Date' is not supported in LINQ to Entities.
I have a code where I have tried to follow the answers of other two other posts: LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method and Linq To Sql compare Time only
Also this method is executed by many threads in parallel.
public List<Element> GetResults()
{
List<Element> elements = new List<Element>();
try {
using (DbContext context = new EntitiesContext())
{
DateTime dateTimeNow = DateTime.Now;
TimeSpan timeSpanNow = DateTime.Now.TimeSpan;
elements = context.Elements.
// Some other Includes
//Element has a field System.DateTime DateTime
.Include(_ => _.DateTime)
.Where(o => DbFunctions.TruncateDate(o.DateTime.Date) == dateTimeNow
&& DbFunctions.CreateTime(o.DateTime.Hour, o.DateTime.Minute, o.DateTime.Second) <= timeSpanNow))
.ToList();
}
}
catch(Exception ex)
{
//logging
}
return elements;
}