EF CTP4 : “The context cannot be used while the model is being created.”

拜拜、爱过 提交于 2019-12-24 04:24:06

问题


I have two entities : Student and Class.

they have a many-to-many relationship between each other :

class Student
{
   ICollection<Class> Classes{get;set;}
}

class Class
{
   ICollection<Student> Students{get;set;}
}

when I try to execute the following statement :

return _db.Students.Where(s => s.Email == email).FirstOrDefault();

I get this error message :

 "The context cannot be used while the model is being created."

回答1:


I had same issue/exception when I forgot to put connection string from the app.config in project where codefirst model was to web.config in webui project from where I was running my app and referenced CF. Maybe not your case, but worth checking.



来源:https://stackoverflow.com/questions/5383809/ef-ctp4-the-context-cannot-be-used-while-the-model-is-being-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!