Multiple Entity Framework Models in the same project
November 16, 2010 1 Comment
Continuing my journey though Entity Frameworks 4.0 Recipes, I have 1 EF Model in a project (Example 2-2). I then added a new model (example 2-4) with a different namespace.
Everything works fine.
I then added a third model with a different namespace
When I try and compile I get a bunch of nasty errors:
I double checked the properties of each of the second and third model – note that the namespace properties are different:
Seeing that they each shared the same Entity Container Name, I changed them and then ran into this error:
I then found my answer – I re-used the connection string. Unfortunately, there is context-specific information in the connection string. When I copy/pasted the connection string:
1 <add name="ProductEntities" 2 connectionString="metadata=res://*/Poetry.csdl|res://*/Poetry.ssdl|res://*/Poetry.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=EFRecipies;Integrated Security=True;MultipleActiveResultSets=True"" 3 providerName="System.Data.EntityClient" />
I found that .csdl, etc… were still referencing the original context. Changing that to the new context (or re-generating the model using a different connection string) did the trick:
Very useful, thanks for the post.