February 19, 2009 18:47 by ColinW
While the Entity Data Model Wizard takes care of most of the housekeeping chores when you add an entity model to your project, it fails to add the necessary reference to your web.config in order for you to reference an Entity from your model.
If you try to access an entity from a view or any other code-front, you end up with the following error:
Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
While the message is quite descriptive, it doesn’t tell you that the reference needs to be added to the web.config, not just in the project references.
The required line you need to add in the assemblies section of your web.config is:
<add assembly="System.Data.Entity, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
I do not think this issue will be resolved in the first release of MVC, as the change would really need to be done in Visual Studio, so be prepared to do a little manual work for the near future.