您如何使Entity框架6 + Sqlite +代码首先工作? [英] How do you make Entity framework 6 + Sqlite + code first work?

查看:119
本文介绍了您如何使Entity框架6 + Sqlite +代码首先工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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


我认为这个错误有些东西与app.config文件有关。
有没有人有一个工作的app.config文件为Entity框架6 + Sqlite 1.0.91?



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

 <?xml version =1.0?> 
< configuration>
< configSections>
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< / configSections>

< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< provider invariantName =System.Data.SQLitetype =System.Data.SQLite.SQLiteProviderServices,System.Data.SQLite.Linq,Version = 1.0.91.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139/ >
< / providers>
< / entityFramework>
< connectionStrings>
< add name =BloggingContextconnectionString =Data Source = .\animals.sqliteproviderName =System.Data.SQLite/>
< / connectionStrings>
< system.data>
< DbProviderFactories>
< remove invariant =System.Data.SQLite/>
< add name =SQLite Data Providerinvariant =System.Data.SQLitedescription =SQLite的数据提供者type =System.Data.SQLite.SQLiteFactory,System.Data.SQLite/> ;
< / DbProviderFactories>
< /system.data>


< startup>< supportedRuntime version =v4.0sku =。NETFramework,Version = v4.0/>< / startup>< / configuration> ;


解决方案

首先从提供程序部分删除以下行: / p>

 < provider invariantName =System.Data.SQLitetype =System.Data.SQLite.SQLiteProviderServices,System.Data。 SQLite.Linq,Version = 1.0.91.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139/> 

添加以下行而不是:

 < provider invariantName =System.Data.SQLitetype =System.Data.SQLite.SQLiteProviderServices,System.Data.SQLite.Linq/>更多信息:使用实体框架6和SQLite的问题 


I am trying to create a simple project to explore how Entity framework 6 code first with sqlite db provider works, but when I complite my app I get the error:

"The Entity Framework provider type 'System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SQLite' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."

I think that this error has something to do with the app.config file. Does anyone has a working app.config file for Entity framework 6 + Sqlite 1.0.91?

These are my config file contents:

    <?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>

解决方案

Firstly remove the below line from the providers section :

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"/>

And add below line instead of that :

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq" />

For more info : Problems using Entity Framework 6 and SQLite

这篇关于您如何使Entity框架6 + Sqlite +代码首先工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆