I am getting the following error:
"An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
Additional information: Unable to create a constant value of type 'Datos.Especialidad'. Only primitive types or enumeration types are supported in this context."
When trying to correct the following code:
IQueryable<Medico> listaMedicos =
from unMedico in context.Medico
select unMedico;
if (medico.Especialidad.Count > 0)
{
listaMedicos = FiltrarPor(listaMedicos,
x => x.Especialidad.Any(e => e.ID == (medico.Especialidad.FirstOrDefault().ID)));
}
return listaMedicos.ToList();
The relationship between "Medico" and "Especialidad" is a many to many as follow
FiltrarPor
doing? You probably just need to capturemedico.Especialidad.FirstOrDefault().ID
in a variable and use that in your lambda instead. – juharrWhere
so they do want aAny
. – juharrvar id = medico.Especialidad.FirstOrDefault().ID;
and thenlistaMedicos = FiltrarPor(listaMedicos, x => x.Especialidad.Any(e => e.ID == id));
– juharr