I have a Problem while I am using Linq for an async result. Every time I get the error "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection." - but I get it only on my local database, when I try the code on our test db everything works...
My code:
var manufacturerData= await _manufacturerDataService.GetAllAsync();
return Json(
manufacturerData.Select(x => new
{
x.Id,
ManufacturerName = x.Manufacturer.Name,
CountryName = x.Country.Name,
x.ProductType,
ContractTypes = x.ContractTypes != null ? string.Join(" ", x.Types.Select(c => c.Name)) : ""
}), JsonRequestBehavior.AllowGet);
I have a backup on my local machine of the test db, so I don't understand why it does not work.
The solution of this problem was not to find in code - the database has a problem. The Id of manufacturer was in some cases null (local).. I think there went something wrong while I imported data from the test db.