Al usar DbFunctions obtengo un error: el miembro de tipo especificado 'Fecha' no es compatible con LINQ to Entities

Using EF 6 when I run this code even using DbFunctions.TruncateTime

var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated.Date) == report.DateCreated.Date);
var test = touches.ToList();

Me sale este error:

El miembro de tipo especificado 'Fecha' no es compatible con LINQ to Entities. Solo se admiten inicializadores, miembros de entidad y propiedades de navegación de entidad.

Any idea how to solve this.

preguntado el 28 de mayo de 14 a las 14:05

This exception is thrown when the property getter returns a (presumably) modified backing field. E.g., the getter return _field.ToString().SubString(1,6) or something along those lines. -

from System.Data.Entity -

1 Respuestas

You can pull the date up into a variable:

var reportDate = report.DateCreated.Date;
var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated) == reportDate);
var test = touches.ToList();

contestado el 28 de mayo de 14 a las 14:05

I get the same error n exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code Additional information: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. - GibboK

I don't understand what you have done here. Other than add an extra line at the start, it's the same code. - davidg

@GibboK sorry, didn't notice the Date on the first part. Try the edited version. - stanley

@DavidG I pulled report.DateCreated.Date out of the lambda into a variable. - stanley

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.