Multiple Entity Framework Models in the same project

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=&quot;Data Source=.;Initial Catalog=EFRecipies;Integrated Security=True;MultipleActiveResultSets=True&quot;" 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:


One Response to Multiple Entity Framework Models in the same project

  1. anon says:

    Very useful, thanks for the post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: