我尝试通过代码第一次尝试连接到EF 6中的新Firebird数据库。系统不会在我尝试插入某些内容之前创建数据库,并且找不到我提供给app.config的数据库提供程序。为什么EF 6无法识别我的Firebird数据库提供程序?
我的项目住在一个库项目,所有的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类的构造函数现有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无法识别坐在配置中的数据库提供程序,因此不会创建数据库?
它现在工作,当我从库项目app.config配置复制到可执行文件app.config。现在我得到一个System.TypeInitializationException异常说:“'System.Data.Entity.Internal.AppConfig'的类型初始值设定项引发异常。” VS编辑器说配置文件格式正确。我捅了一下,看看会发生什么:) – Booser
你是否已经将EF firebird提供程序安装到了可执行项目中?它可能无法读取配置,因为它需要firebird程序集。如果在调试模式下启动应用程序,Visual Studio将在执行过程中停止。如果是这样,你可以检查一些内部执行是否有更具体的信息 – JotaBe
是的,我重新安装了提供程序并将其添加到可执行项目。现在我可以像预期的那样使用它。谢谢。 – Booser