I'm trying to use the View Model Pattern concept, but when I'm implementing the compiler it's having a conversion error.
Below is the approach I used:
Viewmodel structure
public class EvolucaoViewModel
{
public Chamado ChamadoAtual { get; set; }
public virtual ICollection<Evolucao> Evolucoes { get; set; }
}
Implementation in controller
public ActionResult DetalharChamado(int? id)
{
EvolucaoViewModel model = new EvolucaoViewModel();
model.ChamadoAtual = _contexto.Chamados.Find(id);
model.Evolucoes = _contexto.Evolucoes.Where(e => e.id_chamado == id);
ViewBag.id_usuario = new SelectList(_contexto.Usuarios, "id_usuario", "nome_usuario", model.ChamadoAtual.id_usuario).OrderBy(p => p.Text);
ViewBag.id_chamado = id;
ViewBag.id_setor = new SelectList(_contexto.Setores, "id_setor", "nome_setor", model.ChamadoAtual.id_setor);
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
if (model == null)
{
return HttpNotFound();
}
return View(model);
}
When I try to do this assignment, the VS shows me the message below:
model.Evolucoes = _contexto.Evolucoes.Where(e => e.id_chamado == id);
Error 3 Can not implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.ICollection'. E: \ DevSpace \ Projects \ Albasi.Atende \ Albasi.Atende.Web \ Controllers \ CallController.cs 77 31 Albasi.Atende.Web
What do I need to change?