C# 为什么EF 6不能识别我的Firebird数据库提供商?

C# 为什么EF 6不能识别我的Firebird数据库提供商?,c#,.net,entity-framework,firebird2.5,C#,.net,Entity Framework,Firebird2.5,我尝试通过代码第一次尝试连接EF 6中的新Firebird数据库。在我尝试插入某些内容之前,系统不会创建数据库,并且在app.config中找不到我提供的db提供程序 我的项目生活在一个图书馆项目中,所有的EF工作都完成了,一个控制台应用程序显示我返回的数据 我在项目中安装了以下NuGet软件包 实体框架6.1.3 EntityFramework.Firebird.4.8.1 FirebirdSql.Data.FirebirdClient.4.8.1.1 我的配置基本上遵循了传统的配置方法

我尝试通过代码第一次尝试连接EF 6中的新Firebird数据库。在我尝试插入某些内容之前,系统不会创建数据库,并且在app.config中找不到我提供的db提供程序

我的项目生活在一个图书馆项目中,所有的EF工作都完成了,一个控制台应用程序显示我返回的数据

我在项目中安装了以下NuGet软件包

  • 实体框架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>
以及软件环境

public class SoftwareContext : DbContext
{
    public DbSet<Software> Programs { get; set; }

    public SoftwareContext()
    {  }
}
当我明确地将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类的构造函数中检查现有的DbProviderFactorys时,列表仅显示其他提供程序

  • 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不识别配置中的my database provider,因此不创建db?

    您的问题是.NET使用的配置不是库的配置文件中指定的配置,而是主项目中指定的配置。也就是说,如果你的应用程序是一个网站,你需要在
    web.config
    中设置你的配置。如果是控制台或桌面应用程序,则需要将配置添加到该项目的
    app.config
    。而且,如果要运行集成测试,则需要将配置添加到测试项目中


    在所有其他方面,它看起来像您的。

    当我将配置从library projects app.config复制到executables app.config时,它现在可以工作了。现在我得到一个System.TypeInitializationException,它说“System.Data.Entity.Internal.AppConfig的类型初始值设定项引发了一个异常。”VS编辑器说配置文件的格式正确。我四处看看会发生什么:)您是否已将EF firebird提供程序安装到可执行项目中?它可能无法读取配置,因为它需要firebird程序集。如果在调试模式下启动应用程序,Visual Studio将在执行选项上停止。如果是这样,您可以检查某个内部执行选项是否有更具体的信息是的,我重新安装了提供程序,并将其添加到可执行项目中。现在我可以随心所欲地使用它了。非常感谢。
    public SoftwareContext() : base(new FbConnection(constring), true)
    
    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.