System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection

后端 未结 10 2241
清酒与你
清酒与你 2020-12-01 23:21

I am using EF 4 to retrieve a list of Employees.

public ContentResult AutoCompleteResult(string searchText)
{
    List list = Employee.GetAll         


        
10条回答
  •  醉酒成梦
    2020-12-02 00:05

    I prefer to just load up a fat instance declared outside of the using

       Customer _custObj;
            using (RazorOne rz1 = new RazorOne())
            {
                 _custObj = rz1.Customers.FirstOrDefault();      //  .Include = Lazy loading
                // Versus Implicit Load
                _custObj.AddressReference.Load();
                 _custObj.Address1Reference.Load();
            }
    

    Then I can pass her onto the View or whatever helper really wanted her..

提交回复
热议问题