2

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."
Attilah
  • 17,632
  • 38
  • 139
  • 202
  • Do you know that CTP4 is obsolete version? There was already CTP5 with several changes and now you can download EF 4.1 RC: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2dc5ddac-5a96-48b2-878d-b9f49d87569a – Ladislav Mrnka Mar 21 '11 at 21:16

1 Answers1

2

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.

Goran Obradovic
  • 8,951
  • 9
  • 50
  • 79