EF CTP4:"当正在创建的模型的上下文不能使用" [英] EF CTP4 : "The context cannot be used while the model is being created."

查看:211
本文介绍了EF CTP4:"当正在创建的模型的上下文不能使用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体:学生和班级

他们彼此之间的许多一对多的关系:

 班学生
{
   ICollection的<类>类{获取;集;}
}

Class类
{
   ICollection的<学生>学生{获取;集;}
}
 

当我尝试执行以下语句:

 返回_db.Students.Where(S => s.Email ==电子邮件).FirstOrDefault();
 

我收到此错误信息:

 的背景下,不能同时正在创建的模型中使用。
 

解决方案

我有同样的问题/异常时,我忘了把连接字符串从项目中的app.config其中codefirst模式是在WebUI要web.config中从我跑我的应用程序和参考CF.项目 也许不是你的情况,但值得一试。

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."

解决方案

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.

这篇关于EF CTP4:&QUOT;当正在创建的模型的上下文不能使用&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆