为什么 EF 6 无法识别我的 Firebird 数据库提供程序?
Why does the EF 6 not recognize my Firebird database provider?
我尝试通过代码首次尝试连接到 EF 6 中的新 Firebird 数据库。在我尝试插入内容之前系统没有创建数据库并且没有找到我提供给 app.config.
的数据库提供程序
我的项目位于一个库项目中,其中所有 EF 内容都已完成,还有一个显示我返回数据的控制台应用程序。
我在项目中安装了以下 NuGet 包。
- EntityFramework.6.1.3
- EntityFramework.Firebird.4.8.1
- FirebirdSql.Data.FirebirdClient.4.8.1.1
我的配置很少遵循约定优于配置的方法。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="SoftwareContext" connectionString="database=localhost:Inventory;user=user;password=password;ServerType=0;" providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
该模型由一个没有注释的简单 POCO 实现组成。
public class Software
{
public int Id { get; set; }
public string Name { get; set; }
public Version VersionNumber { get; set; }
}
和 SoftwareContext。
public class SoftwareContext : DbContext
{
public DbSet<Software> Programs { get; set; }
public SoftwareContext()
{ }
}
当我 运行 在我创建一个软件对象并将其添加到集合中之前,一切似乎都运行良好。它抛出以下 System.NotSupportedException:
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
当我明确地将 SoftwareContext 的构造函数更改为:
public SoftwareContext() : base(new FbConnection(constring), true)
当我尝试相同的操作时,我得到以下 System.NotSupportedException 抛出:
Unable to determine the provider name for provider factory of type 'FirebirdSql.Data.FirebirdClient.FirebirdClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
当我在我的 SoftwareContext class 的构造函数中检查现有的 DbProviderFactories 时,该列表仅显示其他提供者。
- System.Data.Odbc
- System.Data.OleDb
- System.Data.OracleClient
- System.Data.SqlClient
- System.Data.SqlServerCe.4.0
当我让我给出 Database.DefaultConnectionFactory 时,它总是显示 System.Data.Entity.Infrastructure.SqlConnectionFactory 而不是 app.config 的给定默认值。
EF 和 Firebird 的所有 DLL 在输出中都设置为本地副本。所以它们都在 运行 时间可用。数据库是标准的2.5.5安装无内嵌版本。
我发现了一些关于 EF 和 Firebird 无法正常迁移的主题,但它们大多遇到了其他问题。
为什么 EF 无法识别我位于配置中的数据库提供程序,因此不会创建数据库?
你的问题是.NET使用的配置不是在库的配置文件中指定的,而是在主项目中指定的。 IE。如果您的应用程序是一个网站,您需要在 web.config
中指定您的配置。如果它是控制台或桌面应用程序,则需要将配置添加到该项目的 app.config
。而且,如果你想 运行 集成测试,你需要将配置添加到测试项目。
在所有其他方面,它看起来像您的 configuration is correct。
我尝试通过代码首次尝试连接到 EF 6 中的新 Firebird 数据库。在我尝试插入内容之前系统没有创建数据库并且没有找到我提供给 app.config.
的数据库提供程序我的项目位于一个库项目中,其中所有 EF 内容都已完成,还有一个显示我返回数据的控制台应用程序。
我在项目中安装了以下 NuGet 包。
- EntityFramework.6.1.3
- EntityFramework.Firebird.4.8.1
- FirebirdSql.Data.FirebirdClient.4.8.1.1
我的配置很少遵循约定优于配置的方法。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="SoftwareContext" connectionString="database=localhost:Inventory;user=user;password=password;ServerType=0;" providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
该模型由一个没有注释的简单 POCO 实现组成。
public class Software
{
public int Id { get; set; }
public string Name { get; set; }
public Version VersionNumber { get; set; }
}
和 SoftwareContext。
public class SoftwareContext : DbContext
{
public DbSet<Software> Programs { get; set; }
public SoftwareContext()
{ }
}
当我 运行 在我创建一个软件对象并将其添加到集合中之前,一切似乎都运行良好。它抛出以下 System.NotSupportedException:
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
当我明确地将 SoftwareContext 的构造函数更改为:
public SoftwareContext() : base(new FbConnection(constring), true)
当我尝试相同的操作时,我得到以下 System.NotSupportedException 抛出:
Unable to determine the provider name for provider factory of type 'FirebirdSql.Data.FirebirdClient.FirebirdClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
当我在我的 SoftwareContext class 的构造函数中检查现有的 DbProviderFactories 时,该列表仅显示其他提供者。
- System.Data.Odbc
- System.Data.OleDb
- System.Data.OracleClient
- System.Data.SqlClient
- System.Data.SqlServerCe.4.0
当我让我给出 Database.DefaultConnectionFactory 时,它总是显示 System.Data.Entity.Infrastructure.SqlConnectionFactory 而不是 app.config 的给定默认值。
EF 和 Firebird 的所有 DLL 在输出中都设置为本地副本。所以它们都在 运行 时间可用。数据库是标准的2.5.5安装无内嵌版本。
我发现了一些关于 EF 和 Firebird 无法正常迁移的主题,但它们大多遇到了其他问题。
为什么 EF 无法识别我位于配置中的数据库提供程序,因此不会创建数据库?
你的问题是.NET使用的配置不是在库的配置文件中指定的,而是在主项目中指定的。 IE。如果您的应用程序是一个网站,您需要在 web.config
中指定您的配置。如果它是控制台或桌面应用程序,则需要将配置添加到该项目的 app.config
。而且,如果你想 运行 集成测试,你需要将配置添加到测试项目。
在所有其他方面,它看起来像您的 configuration is correct。