4
I’m trying to make a query
where I check if the day week is chosen to create a list of data that loads in a Viewmodel.
Query:
var plan = db.Servicos.Where(s => (TecnicoResp.HasValue ? s.NumTransportado == TecnicoResp.Value : true)
&& ((IdFornecedor.HasValue ? s.FornecedorID == IdFornecedor : true) && (estabelecimentosDrop.HasValue ? s.EstabelecimentoID == estabelecimentosDrop : true))
&& (IdFornecedor.HasValue ? s.FornecedorID == IdFornecedor : true)
).SelectMany(sc => sc.Planeamento).Where(p => (checkQua == "Sim" ? p.DataAssistenciaProgramada.Value.DayOfWeek == DayOfWeek.Wednesday:true));
//O erro encontra-se no where a seguir ao SelectMany
List<FiltroSPlaneamentoViewModel> resultPlaneamento = FiltroSPlaneamentoViewModel.carregaListaSPlanPlanemaneto(plan.ToList());
So I see if past value checkQua
is "Sim"
, and if it is I will get the dates where the day of the week is Wednesday. I think the error is from here, because when sending the data to the Viewmodel resultPlaneamento
get the following error:
The specified type member 'DayOfWeek' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Yeah, I know I can’t use the
DayOfWeek
in LINK. I don’t know how to solve the problem. I can use Datepart even in the query?– CesarMiguel
I see no problems... can use anywhere in the query LINQ to entities.
– Miguel Angelo