4
I’m generating a report in an app that I’m developing, but I have a little problem. When sending a query in a date interval, I can’t get anything, because it is a DATETIME (I can’t change to date only, because I need the time in a few moments). So I’m trying to send only Date, but it returns an error.
Message = "The specified type Member 'Date' is not supported in LINQ to Entities. Only initializers, Entity Members, and Entity navigation properties are supported."
var query = from td in this.Table.AsNoTracking()
join u in base.context.Users on td.UserId equals u.Id
where (!onlyEnabled) || (u.Enable)
select td;
//AQUI TENTO PASSAR APENAS O DATE
if (initialOpeningDate.HasValue)
query = query.Where(td => DbFunctions.TruncateTime(td.OpeningDate.Date) >= initialOpeningDate.Value);
//AQUI TENTO PASSAR APENAS O DATE
if (finalOpeningDate.HasValue)
query = query.Where(td => DbFunctions.TruncateTime(td.OpeningDate.Date) <= finalOpeningDate.Value);
if (onlyExpired)
query = query.Where(td => td.ExpireDate < DateTime.Now);
return query.ToList();
Really, missed it. But keeps repeating the same mistake.
– Vinícius
I forgot to mention, I’m using the EF.
– Vinícius
@Viniciusmatos Adjusted the answer. See now.
– Leonel Sanches da Silva
I managed to fix it. The problem was . Date at the end. It was "breaking" my query. But, thank you.
– Vinícius