6
I’m having a problem returning a Json using Entity Framework. The code I’m using is:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult Item(int agendaHorarioID)
{
using (var db = new ERPContext())
{
IList<AgendaHorario> agendaHorario = db.AgendaHorario.Where(w => w.AgendaHorarioID == agendaHorarioID).ToList();
var teste = agendaHorario.ToArray();
return Json(new { HttpStatusCode.OK, dados = teste }, JsonRequestBehavior.AllowGet);
}
}
The mistake that happens is:
A instância de ObjectContext foi descartada e não pode mais ser usada para operações que exijam uma conexão.
The reason for the problem I know, the object was not transformed into an array to take the dependency from the Entity Framework. I’ve tried many ways but I couldn’t.
Buddy, I don’t work with EF, I work with Nhibernate, and things are similar, I believe a way to fix this problem and work with DTO’s in the View, and serialize objects without ORM control objects, another way is to overwrite your JSON serializer, to ignore ORM control objects, in NH I do something thus, in EF there must be something to simulate. It’s just a hint.
– Fernando Leal
@Marlon.Tiedt where exactly the error to (which line), because what you did should work without such error ?
– user6026