2011-03-21 82 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。 也許不是你的情況,但值得檢查。