2011-03-21 84 views
2

我有两个实体:Student和Class。EF CTP4:“创建模型时无法使用上下文。”

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

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

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

当我尝试执行以下语句:

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

我收到此错误信息:

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

你知道CTP4是过时的版本吗?已经有几个变化的CTP5,现在你可以下载EF 4.1 RC:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2dc5ddac-5a96-48b2-878d-b9f49d87569a – 2011-03-21 21:16:26

+0

感谢新闻,@拉迪斯拉夫。 – Attilah 2011-03-21 21:17:40

回答

2

当我忘记将app.config中的连接字符串放在proj中时,我遇到了同样的问题/异常其中codefirst模型是从我运行我的应用程序和引用CF的webui项目中的web.config。 也许不是你的情况,但值得检查。