Even before you call the .ToList()
of your query all that code will try to move to SQL statement, for which some functions like you have in the exception could not be translated into SQL, so here you have two options:
To your query you can add .Tolist()
after Where
. With this you would have the objects in memory and the .Select
could apply the format that you are indicating without problems.
It should be noted that in ToList()
, you would only be bringing the entities of ActividadesUser
and as in select
you need data of Usuario
and Actividades
, it is necessary that addition .Include(
to include the relationships of the entities Daughters . Your query would be this way for example:
db.ActividadesUser
.Include(x => x.User)
.Include(x => x.Actividades)
.Where(x => x.UserId == usuario)
.ToList()
.Select(x => new ActividadesViewModel
{
UsuarioId = x.User.Email,
Actividad = x.Actividades.Actividad,
Descripcion = x.Actividades.Descripcion,
Fecha = string.Format("{0:ddd (MMMM yyyy)}", x.Actividades.Fecha)
}).ToList()
Do not apply the format in the .Select(
, work with the type datetime
instead of string
and format it in your view.
Greetings, I hope you serve