社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
http://blog.csdn.net/hlinkkk/article/details/51870820
之前一直用SQLServer,最近项目需要,要转到SQLite上来。在尝试用VS2013+EF6集成SQLite的过程中,走了不少弯路,现在做一个记录。
一、软件环境
Win7 64位+Visual Studio Ultimate 2013
Microsoft .NET FrameworkVersion :4.5.51641
二、配置过程
1、访问https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki,下载最新的SQLite支持包。
要注意的是,无论你的VS2013是64位还是32位,都要下载X86带bundle后缀的版本。64位的版本没有带VS的插件。
另外,一定要下载最新的。之前网上推荐的都是sqlite-netFx451-setup-bundle-x86-2013-1.0.98.0,结果安装后在VS中打开的时候就出现包不匹配的错误。
截止到2016-07-10,最新的能用在VS2013上的安装包应该是sqlite-netFx451-setup-bundle-x86-2013-1.0.102.0.exe
下载后完全安装就可以。
2、打开VS,新建一个工程,用nuget获取SQLite相关的支持包
主要有下图几个:
搜索安装图中的第一个包,nuget就会根据依赖性自动下载安装其余的包。
安装完成后,项目的config文件中会自动添加相应的配置项。
3、安装完成后,编译一次项目,然后就可以在项目中添加实体数据对象了。
配置文件:
<?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>
<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" />
<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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<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" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<connectionStrings>
<add name="WirelessDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=D:WirelessDB.db"" providerName="System.Data.EntityClient"
/>
</connectionStrings>
</configuration>
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!