Entity Framework and Web API ObjectDisposedException

后端 未结 3 1873
予麋鹿
予麋鹿 2021-01-14 18:15

I have a data layer that uses Entity Framework 5 to connects to Sql Server. I also have a LINQ query that gets some data. This query fails when used with Web API. I get the

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 18:38

    This happens because lazy loading is being performed after your DbContext has been disposed.

    To resolve the issue you can disable lazy loading by doing this:

    container.Configuration.LazyLoadingEnabled = false;
    

提交回复
热议问题