Entity Framework - Use 2 DBContext for the same Database

c# entity-framework entity-framework-6

Question

I have a solution where I want to add another project with it's own DBcontext, using its own tables, in the same database as the rest of the solution (the 2 DBcontexts are not sharing any tables). But when running the project I am getting the error below:

Additional information: The default DbConfiguration instance was used by the Entity Framework before the 'Configuration' type was discovered. An instance of 'Configuration' must be set at application start before using any Entity Framework features or must be registered in the application's config file.

I already have a big database built in the existing solution, so I don't want to change anything there, if I can avoid that. I have tried to change the ContextKey in the configuration and also tried to use another DB schema for the new project, but I'm still getting the error.

1
2
12/11/2015 10:47:26 AM

Popular Answer

The link provided in the first comment to the question by steve-green solves the issue.

From https://msdn.microsoft.com/en-us/data/jj680699#Moving:

... use the config file to specify the DbConfiguration instance to use. To do this, set the codeConfigurationType attribute of the entityFramework section. For example:
<entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly"> ...Your EF config... </entityFramework>

1
5/23/2017 12:10:32 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow