none
EF6 - More than one factory RRS feed

  • Question

  • Hello.

    I can use EF6 (allways Code First) with no problem with SQL Server, SQL Server Compact Edition, Firebird, Oracle and Firebird, as I've made. And I really love it.

    But I'm having with some problems.

    When I try to use it with MySql always get a problem with key's sizes (__MigrationHistory for example). This issue is persistent and the "solution" isn't elegant, requiring several "manual" interventions. The "solution" looks like some "jerry-built".

    Now I need to use two different database engines, MySql and SQL Server Compact, in the same application, and the first problem is how to define the defaultConnectionFactory.

    The application raises the error message:

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

    In EF section I have:

    <providers>
      <provider invariantName="MySql.Data.MySqlClient"      type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
      <provider invariantName="System.Data.SqlClient"       type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>

    The defaultConnectionFactory section I've tested are:

    <defaultConnectionFactory codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
      <parameters>
        <parameter value="MySql.Data.MySqlClient" />
      </parameters>
    </defaultConnectionFactory>

    <defaultConnectionFactory codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>

    And of course, I've tried just supress the defaultConnectionFactory section.

    With those configurations above, I've got problems.

    Can you help me to solve those problems?

    Thanks.

    Friday, July 24, 2015 6:10 PM

Answers

  • Hi JLOS,

    According to your description, you'd like to use MySql and Sql server at the same time.<o:p></o:p>

    It's hard to make this with one DbContext, You'd better to use two DbContexts for each
    DataBase.

    Regards,

    Youjun Tang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, July 29, 2015 4:06 AM

All replies

  • Hi JLOS,

    According to your description, you'd like to use MySql and Sql server at the same time.<o:p></o:p>

    It's hard to make this with one DbContext, You'd better to use two DbContexts for each
    DataBase.

    Regards,

    Youjun Tang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, July 29, 2015 4:06 AM
  • Hello, Youjun Tang

    Thank you by the answer.

    Yes, I'd like to use both in the same application, but no, not at same time nor in the same DbContext.

    To better explain, I've an application that is working fine if I use SQL Server / SQL Server Compact, or SQL Server / Firebird. A few weeks ago, a new customer asks me to replace the SQL Server with MySql, so, I made the required changes. The problems begin at this point: Using MySql Net Connector 6.9.7 / EF 6.1.3. I've a lot of error messages, for example, "The sequence contains no matching elements", "Schema specified is not valid" and others.

    So, I think the problem is on MySql, since I run the app with no problems with SQL Server and SQL Server Compact or SQL Server and Firebird.

    Maybe there is something different to make when using MySql. Because of it, I'm looking for some example, or  book, or something like "step-by-step".

    In time: If I use the MySql components (MySqlConnector, MySqlDataAdapter etc) to "manually" do the tasks (check / create the tables, run the DML queries etc) I've no error messages, no problems.

    Ghost in the machine!

    Monday, August 10, 2015 12:13 AM