0
I have my classes:
public class Bandeira
{
public int BandeiraID { get; set; }
public string Nome { get; set; }
public virtual ICollection<Curso> Cursos { get; set; }
}
public class Curso
{
public int CursoID { get; set; }
public virtual int BandeiraID { get; set; }
public virtual Bandeira Bandeira { get; set; }
}
The method of my repository:
public IQueryable<TEntity> Get(Func<TEntity, bool> predicate, string[] includes)
{
var query = GetAll().Where(predicate).AsQueryable();
foreach (var include in includes)
{
query = query.Include(include);
}
return query;
}
My Controller:
var bdCurso = new CursoRepositorioEF(contexto);
var curso = bdCurso.Get(x => x.CursoID == id, new string[] { "Bandeira" }).FirstOrDefault();
bdCurso.Dispose();
if (curso == null)
return RedirectToAction("Index");
return View(curso);
So my View:
@model Aplicacao.Core.Dominio.Curso
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.CursoID)
@Html.Display("teste", Model.Bandeira.Nome, new { @class = "form-control", @disabled = "disabled" })
}
Generates the following error in the View:
An Exception of type 'System.Objectdisposedexception' occurred in Entityframework.dll but was not handled in user code
Additional information: The Objectcontext instance has been disposed and can no longer be used for Operations that require a Connection.