你如何使Entity框架6 + Sqlite +代码首先工作?

Yia*_*lis 12 sqlite entity-framework

我正在尝试创建一个简单的项目来探索实体框架6代码如何首先与sqlite数据库提供程序一起工作,但当我完成我的应用程序时,我得到错误:

"实体框架提供程序类型'System.Data.SQLite.SQLiteProviderServices,System.Data.SQLite.Linq,Version = 1.0.91.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'在ADO.NET提供程序的应用程序配置文件中注册无法加载不变名称'System.Data.SQLite'.请确保使用程序集限定名称并且程序集可供正在运行的应用程序使用.请参阅 http://go.microsoft.com/fwlink/?LinkId = 260882了解更多信息."

我认为这个错误与app.config文件有关.有没有人为Entity framework 6 + Sqlite 1.0.91提供有效的app.config文件?

这些是我的配置文件内容:

    <?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"/>
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="BloggingContext" connectionString="Data Source=.\animals.sqlite" providerName="System.Data.SQLite"/>
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite"/>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
    </DbProviderFactories>
  </system.data>


<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Run Code Online (Sandbox Code Playgroud)

Sam*_*ath 2

首先从提供者部分删除以下行:

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"/>
Run Code Online (Sandbox Code Playgroud)

并添加以下行来代替:

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq" />
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息:使用Entity Framework 6和SQLite的问题