C# - The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

后端 未结 5 1864
时光说笑
时光说笑 2021-01-19 08:29

I\'m sorry for the repetition. I\'m heading with a same problem but still could not handle it. I\'m using Angularjs framework and Asp.net mvc.

My person class:

5条回答
  •  无人及你
    2021-01-19 08:36

    The problem is solved. I get help from my friend. Its about unclosed connection. Its my fault. I didn't mention it.

    In PersonIndexVM(), I created People = new List(); Person class is created by entity framework. It is related with database. When I create a model that is an object of PersonIndexVM() in GetPeople() method and return this model object as a json, model object try to reach User class informations after the connection closed. And I'm getting this error. To solve this problem:

    1. Closing the lazy loading to prevent reaching User information. dc.Configuration.LazyLoadingEnabled = false;

    2. Creating another class not related with database and return its object as Json.

提交回复
热议问题