EF SQLite

1.通过NuGet添加程序集的相关引用

  Install-Package System.Data.SQLite

2.安装类似SQL的插件

  地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

  注意:1.现在支持VS2013的名字:sqlite-netFx451-setup-bundle-x86-2013-1.0.101.0.exe ,需要下载bundle的文件,支持VS插件,2013代表支持VS2013,下载页会有相关的其他的下载链接以及支持的VS版本

3.配置文件添加

  配置文件添加

  <system.data>
      <DbProviderFactories>
        <remove invariant=”System.Data.SQLite”/>
        <add name=”SQLite Data Provider” invariant=”System.Data.SQLite” description=”.Net Framework Data Provider for SQLite” type=”System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.57.0,         Culture=neutral, PublicKeyToken=db937bc2d44ff139″ />
      </DbProviderFactories>
   </system.data>

4.完整的配置文件,仅参考

  

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


  <connectionStrings>
    <add name="TestDataBase" providerName="System.Data.SQLite.EF6" connectionString="Data Source=c:\mydb.db;Password=admin;" />
    <add name="test" providerName="System.Data.SQLite.EF6" connectionString="Data Source=F:\CodeLibrary\test.db;Password=19890625;" />
  <add name="testEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=F:\CodeLibrary\test.db;password=19890625&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
  
  <system.data>
    
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
    
  </system.data>
  
  <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.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
    
  </entityFramework>
  
</configuration>

 

 

  

    原文作者:sqlite
    原文地址: https://www.cnblogs.com/yanlovehan/p/5435234.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞