0
I am receiving an array of values from my View with the days of the week. Sunday, Monday, etc. I want to compare this array with a string type attribute of my database and store it in a "Iqueryable" type variable. And add up the contents of the tables. But C# won’t let me add that variable.
public JsonResult GetCatequizandosByDiasDisponiveis(string[] diasPertendidos, string anoCatequese)
{
var catequizandosPorDiasDisponiveis = (from i in db.Inscricao
join c in db.Catequizando on i.CatequizandoID equals c.CatequizandoID
join p in db.Pessoa on c.CatequizandoID equals p.PessoaID
where i.AnoCatequese == anoCatequese
select new {
PessoaID = p.PessoaID,
Nome = p.Nome,
Dispo = i.Dias_Preferencial
});
foreach (string dia in diasPertendidos ?? Enumerable.Empty<string>())
{
// para cada 'dia' ver quais os catequizandos possiveis <--- catequizandosPorDiasDisponiveis
// depois, juntar tudo e eliminar os repetidos
catequizandosPorDiasDisponiveis += catequizandosPorDiasDisponiveis.Where(d => d.Dispo.Contains(dia));
}
return Json(catequizandosPorDiasDisponiveis, JsonRequestBehavior.AllowGet);
}
My problems are here:
CatechetiesPortsDailable += Where(d => d.Contains(day));
O had already made a Join to my array, but so returns all the people who had chosen "Sunday AND Monday" and not "Sunday OR Monday". So I was trying to make a counter inside my foreach I don’t know if I’m being explicit.
– Simão Lopes
@Simãolopes make a group by the day.
– Bruno Costa
Inside the foreach ?
– Simão Lopes
There is no way to increment variables of the type Iqueryable?
– Simão Lopes
Simon, from what I understand, in your Entity
Inscrito
, you have a propertyDias_Preferencial
which is aList<String>
with the dates, like["Domingo", "Segunda", "Terça"]
and the arraydiasPertendidos
is a similar list... you wantInscrito.Dias_Preferencial
has all the values ofdiasPertendidos
or at least one?– Tobias Mesquita
At least one value.
– Simão Lopes
I did "string convertestringdias = string. Join(",", dayPertendidos);" , "! dayPertendidos.Except(i.Dias_preferential). Any()", and does not return data
– Simão Lopes