我有两个实体框架上下文,一个用于MySql,一个用于sql。如果我运行应用程序,我得到以下错误是否有可能为MySql和SqlServer提供EF上下文?
The default DbConfiguration instance was used by the Entity Framework before the 'MySqlEFConfiguration' type was discovered.
但是,如果我这样做给它的Database.SetInitializer<MySqlContext>
发现在App启动数据库类型,我正常的SQL上下文目前正试图使用mysql提供连接。
我的MySQL语境
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ZipCodeContext : DbContext
{
public DbSet<ZipCode> ZipCodes { get; set; }
}
我正常的语境
public class MyContext : DbContext
{
public DbSet<MyClass> MyClasses{get;set;}
}
,最后我的web配置为实体框架部分
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
我希望这是很清楚的,我m把我的头撞在桌子上
你有没有设法解决这个问题? – James
负面的@詹姆斯,从来没有设法弄清楚。我最终只使用普通的MySql连接并从那里执行查询。 – tympaniplayer
谢谢你的跟进,我会告诉你,如果我设法得到这个 – James