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

后端 未结 5 1884
时光说笑
时光说笑 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:58

    You can strongly type your inclusion, which will give you hints as to whether or not your object structure is correctly related. This solves any "magic strings" issues, such as your table being named Users instead of User inside of your EF context, after including DbExtension.

    using System.Data.Entity.DbExtension;
    model.People = dc.People.Include(c => c.User).ToList();
    

    However, if you are using ObjectContext instead of DbContext, you may be stuck with magic strings. That said, EF will "pluralize" most names, so your table is most likely named "Users". Check to see if the table exists as dc.Users and, if it does, change your magic string to match.

    model.People = dc.People.Include("Users").ToList();
    

提交回复
热议问题