简体   繁体   中英

Only on local database: ObjectContext instance has been disposed

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM