EF本身支持sqllite的映射,本文所使用的库版本EntityFramework 6.1.3,sqlite 1.0.104。
1、通过Nuget下载EntityFramework 6.1.3,sqlite 1.0.104
2、App.config配置
<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> <entityFramework> <providers> <provider invariantName="System.Data.sqlite.EF6" type="System.Data.sqlite.EF6.sqliteProviderServices,System.Data.sqlite.EF6" /> </providers> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <connectionStrings> <add name="NorthwindContext" connectionString="Data Source=|DataDirectory|\db.sqlite" providerName="System.Data.sqlite.EF6" /> </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" /> </DbProviderFactories> </system.data> </configuration>
3、继承DbContext,并定义实体,其他操作类型搭建sql Server环境
4、vs2015 “程序包管理控制台”中输入Enable-Migrations命令,启用迁移命令
6、输入update-database ,更新数据库
参考网址:http://www.cnblogs.com/kaito/p/3638112.html
原文链接:https://www.f2er.com/sqlite/198558.html