1
I wanted to list the names belonging to a group and send to a Viewmodel and be collected by a View(details). Problem:
'Iqueryable' does not contain a Definition for 'Catechetizing' and in the Extension method 'Catechetizing' Accepting a first argument of type 'Iqueryable' could be found (are you Missing a using Directive or an Assembly Reference?)
Controller:
public ActionResult Detalhes(int? id)
{
var grupo = db.Grupo.Where(g => g.GrupoID ==id).FirstOrDefault();
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
//query para recolher as nomes dos catequizandos pertencentes ao grupo selecionado
var queryNomeCatequizandos = (from g in db.Grupo
join i in db.Inscricao on g.GrupoID equals i.GrupoID
join c in db.Catequizando on i.CatequizandoID equals c.CatequizandoID
join p in db.Pessoa on c.CatequizandoID equals p.PessoaID
where g.GrupoID == i.GrupoID && i.CatequizandoID == c.CatequizandoID && c.CatequizandoID == p.PessoaID && g.GrupoID == id
select new GrupoViewModel
{
NomeCatequizando = p.Nome,
});
if (queryNomeCatequizandos == null)
{
return HttpNotFound();
}
GrupoViewModel model = new GrupoViewModel()
{
GrupoID = grupo.GrupoID,
NomeCatequizando = queryNomeCatequizandos.NomeCatequizando,
};
return View(grupo);
}
Viewmodel:
public class GrupoViewModel
{
public int GrupoID { get; set; }
public String AnoPastoral { get; set; }
public String HoraInicio { get; set; }
public String DiaSessao { get; set; }
public String AnoCatequese { get; set; }
public String LetraGrupo { get; set; }
public String Sala { get; set; }
public String Observacoes { get; set; }
public String NomeCatequizando { get; set; }
}
You have a problem: Inscription model
public int? Grupoid { get; set; }
Controller error:
GrupoID = i.GrupoID,
Error:
Cannot implicitly Convert type 'int? ' to 'int'. An Explicit Conversion exists (are you Missing a cast?)
There is a problem the group is not required.
– Simão Lopes
You should have put that in the question. If it’s not mandatory, how will you select by the sentence you put?
– Leonel Sanches da Silva
I am Portuguese and didn’t notice the context in the word "sentence", but an Inscription may or may not be related to a group. that is, Foreignkey may be null.
– Simão Lopes
"Sentencing" in Brazilian Portuguese is the query Linq. Anyway, I put an improvement on the answer.
– Leonel Sanches da Silva
Another problem arose in my View, I wanted to send more information to the View, other than the list of Names, such as "Lettering", "room", etc, which is not of the Ienumerable type. How can I solve this problem?
– Simão Lopes
Filling more things in Viewmodel and grouping into View. Open up another question, please.
– Leonel Sanches da Silva