I would to make an ASP.NET MVC API with data from my database. To do this I use LINQ. I create my context and get all tariffs where delete
is false.
[HttpGet]
public JsonResult Index()
{
List<Tariff> temp = new List<Tariff>();
using (Context context = new Context())
{
temp = context.Tariff.Where(t => !t.Delete).ToList<Tariff>();
}
return Json(temp, JsonRequestBehavior.AllowGet);
}
When I debug, temp contains a List of System.Data.Entity.DynamicProxies.Tariff_...
instead of MyNamespace.Models.Tariff
. When I continue it gives me this exception:
The
ObjectContext
instance has been disposed and can no longer be used for operations that require a connection.
What I'm doing wrong?