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);
Then 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" })
}
Generate the following error in 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 provisioned and can not be used for operations that require a connection.