2015-11-30 38 views
0

我嘗試通過代碼第一次嘗試連接到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列表中只顯示其他供應商。

  1. System.Data.Odbc
  2. System.Data.OleDb
  3. System.Data.OracleClient的
  4. System.Data.SqlClient的
  5. System.Data.SqlServerCe.4.0

當我讓我給的Database.DefaultConnectionFactory它總是顯示我System.Data.Entity.Infrastructure.SqlConnectionFactory不是給定的默認值從app.config。

所有EF和Firebird的DLL被設置爲輸出的本地副本。所以它們在運行時都可用。該數據庫是一個標準的2.5.5安裝沒有嵌入式版本。

,我發現關於EF和Firebird的工作不遷移的一些話題,但他們大多是讓其他的問題。

爲什麼EF無法識別坐在配置中的數據庫提供程序,因此不會創建數據庫?

回答

2

你的問題是.NET所使用的配置不是在庫的配置文件中指定的,而是在主項目中的配置文件。即如果你的應用程序是一個網站,你需要在web.config中增加你的配置。如果它是控制檯或桌面應用程序,則需要將您的配置添加到該項目的app.config。而且,如果您想運行集成測試,則需要將配置添加到測試項目中。

在所有其他方面,它看起來像你的configuration is correct

+0

它現在工作,當我從庫項目app.config配置複製到可執行文件app.config。現在我得到一個System.TypeInitializationException異常說:「'System.Data.Entity.Internal.AppConfig'的類型初始值設定項引發異常。」 VS編輯器說配置文件格式正確。我捅了一下,看看會發生什麼:) – Booser

+1

你是否已經將EF firebird提供程序安裝到了可執行項​​目中?它可能無法讀取配置,因爲它需要firebird程序集。如果在調試模式下啓動應用程序,Visual Studio將在執行過程中停止。如果是這樣,你可以檢查一些內部執行是否有更具體的信息 – JotaBe

+0

是的,我重新安裝了提供程序並將其添加到可執行項目。現在我可以像預期的那樣使用它。謝謝。 – Booser

相關問題