[英]Entity Framework keeps trying to connect to old ADO.NET provider eventhough it has been changed
I changed a MySQL project's DB connection to target SQL Server from MySQL. 我将MySQL项目的数据库连接更改为从MySQL定位到SQL Server。 However, when trying to run
Update-Database -StartProjectName ProjectName
targeting a database in SQL Server, I receive the following error 但是,当尝试运行针对SQL Server中的数据库的
Update-Database -StartProjectName ProjectName
,出现以下错误
Schema specified is not valid.
指定的架构无效。 Errors: (0,0) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'.
错误:(0,0):错误0152:未找到具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序的实体框架提供程序。 Make sure the provider is registered in the 'entityFramework' section of the application config file.
确保提供程序已在应用程序配置文件的“ entityFramework”部分中注册。 See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882 。
So I tried to ensure that my project was free of MySQL 所以我试图确保我的项目没有MySQL
Why does Entity Framework keep asking me for MySQL provider when I have clearly indicated that it should use the default MS SQL provider in the config file? 当我明确指出它应该在配置文件中使用默认的MS SQL提供程序时,为什么Entity Framework一直问我MySQL提供程序?
This is my config file: 这是我的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="Connection" connectionString="Data Source=SQLSERVER123;Database=DB123;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
This is my DbContext file: 这是我的DbContext文件:
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace ProjectName.MSSQL
{
public class ProjectNameContext:DbContext
{
public ProjectNameContext()
: base("Connection")
{
}
public static ProjectNameContext Create()
{
return new ProjectNameContext();
}
public DbSet<Users> Users { get; set; }
}
}
So what worked for me was I created my own DbConfiguration
class and referenced it using the codeConfigurationType property in App.config
所以对我
DbConfiguration
是我创建了自己的DbConfiguration
类,并使用App.config
的codeConfigurationType属性对其进行了引用
My custom Dbconfiguration
class 我的自定义
Dbconfiguration
类
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServer;
namespace ProjectName.MSSQL
{
public class MSSQLDbConfiguration:DbConfiguration
{
public MSSQLDbConfiguration()
{
this.SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
this.SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
}
}
}
My App.config 我的App.config
<entityFramework codeConfigurationType="ProjectName.MSSQL.MSSQLDbConfiguration, ProjectName.MSSQL">
...
any stuff...
...
</entityFramework>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.