2

I'm trying to port my MVC 5 application to MVC 6. I'm using Devart dotConnect for MySql and Oracle. I have trouble configuring my application.

Right now I have the following entries:

<entityFramework>
    <providers>
        <provider invariantName="Devart.Data.MySql" type="Devart.Data.MySql.Entity.MySqlEntityProviderServices, Devart.Data.MySql.Entity" />
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    </entityFramework>
    <system.data>
    <DbProviderFactories>
        <remove invariant="Devart.Data.MySql" />
        <add name="dotConnect for MySQL" invariant="Devart.Data.MySql" description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql" />
    </DbProviderFactories>
</system.data>

My application have 3 DbContext classes (2x MySql, 1x Oracle) in separate assemblies, and I can only have 1 DbConfiguration class (Entity Framework 6 limitation).

If I set this configuration other contexts complain that they cannot see assembly with DbConfiguration class.

How do I get over that limitation?

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
Shadow
  • 2,089
  • 2
  • 23
  • 45
  • Look at [the recent question](http://stackoverflow.com/q/34161278/315935). It could be probably what you need. – Oleg Dec 21 '15 at 17:45
  • @Oleg - I don't think EF6 and EF7 work the same way at this level – Pawel Dec 21 '15 at 19:06
  • @Pawel: I interpret the question so, that one want to migrate from Entity Framework 6 to EF7 in the same way like one migrate from MVC 5 to MVC 6. One described the current configuration in EF6 and want to migrate to EF7. It's my interpretation of the question. EF7 don't have `DbConfiguration`, but one can define and use multiple `DbContext` classes, with connections to different databases. On the other side I don't know whether providers for MySql and Oracle are already available at least as beta. If one don't have anyone then the usage of ASP.NET 5 would be too early. – Oleg Dec 21 '15 at 19:40
  • I want to stay with EF6 (because there are no providers for MySql and Oracle), but migrate to MVC6 – Shadow Dec 22 '15 at 08:22

1 Answers1

-2

I found myself in a similar situation the other day, and had to rely on web.config to enrich the configuration

<entityFramework codeConfigurationType="MyNamespace.MyDbConfiguration, MyAssembly">
...Your EF config...
</entityFramework>

Edit

The second option is to place DbConfigurationTypeAttribute on your context class

[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyContextContext : DbContext
{
}

For more details check these resources

Ef6 docs: Code-Based Configuration Type (EF6 Onwards)

Ef6 docs: Moving DbConfiguration

Dan Dohotaru
  • 2,809
  • 19
  • 15
  • Of course it doesn't. I might have left some context out of view, but my reply is also related to migrating an existing web api from asp.net to asp.net core (keeping both of them alive for a while). They both rely on the very same ef6 implementation (hence being forced to target .net framework till swapping to entity framework core) – Dan Dohotaru Sep 07 '18 at 08:48
  • So I do not understand how Your answer is relevant if config is not loaded. Your reply is totally out of context. – Shadow Sep 07 '18 at 09:53
  • Edit is relevant, however it is not good solution, because all DbContexts in application need reference to that class, so if You have decoupled plugins You have mess. Also if You have plugins with different db providers You have to reference all database drivers. Kind of works for simple cases, but cannot replace config file. – Shadow Sep 07 '18 at 11:03