Correct use of multiple edmx EF 5.0 in one solution

In this example, I am using the first database approach. Due to a manageability issue with one edmx, I decided to split a single edmx into multiple edmxs.

I created a project and added a new ADO.net Entity Data Model called AModel . This gave me the option to select DBNameEntities for the Save Entity connection line in App.config . As a result, the context is created as:

public partial class DBNameEntities: DbContext

Now I have added another Entity Data Model called BModel . I made it possible to select DBNameEntities1 as the connection string for the "Save Entity connection" line in the App.config. Since I already have a connection string that I created for the AModel , I deselected for the connection string. Now the context for the BModel is created like (POCO objects created from T4 template):

public partial class Objects: DbContext

  • In one project, can multiple dbContexts (DBNameEntities, Entities) be used for multiple models?

  • Or is it advisable to use only one dbContext in one project, but split the models into many with different edmxs?

  • How can I use the same connection string as DBNameEntities for multiple models, yet create meaningful contexts at the same time. I wanted the context for the BModel to be generated as BContext and the context for the AModel to be generated as AContext . eg. public partial class AContext: DbContext

  • The correct approach to solve my problem is to create different projects and each project has a model , not to use one project with multiple edmx.

Share your ideas.

+3


source to share





All Articles