Solving “The ObjectContext instance has been disposed and can no longer be used for operations that require a connection” InvalidOperationException

前端 未结 7 2214
再見小時候
再見小時候 2020-11-22 06:38

I am trying to populate a GridView using Entity Frameworkm but every time I am getting the following error:

\"Property accessor \'LoanPro

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 06:48

    In my case, I was passsing all models 'Users' to column and it wasn't mapped correctly, so I just passed 'Users.Name' and it fixed it.

    var data = db.ApplicationTranceLogs 
                 .Include(q=>q.Users)
                 .Include(q => q.LookupItems) 
                 .Select(q => new { Id = q.Id, FormatDate = q.Date.ToString("yyyy/MM/dd"), ***Users = q.Users,*** ProcessType = q.ProcessType, CoreProcessId = q.CoreProcessId, Data = q.Data }) 
                 .ToList();
    
    var data = db.ApplicationTranceLogs 
                 .Include(q=>q.Users).Include(q => q.LookupItems) 
                 .Select(q => new { Id = q.Id, FormatDate = q.Date.ToString("yyyy/MM/dd"), ***Users = q.Users.Name***, ProcessType = q.ProcessType, CoreProcessId = q.CoreProcessId, Data = q.Data }) 
                 .ToList();
    

提交回复
热议问题