EF With SQLite
EF 虽说官方声称支持SQLite,但实际用起来还真没有SQLSever好使。
- 不支持真正的CodeFirst,需要先建表结构。
- 不支支持Migration
- 需要修改App.config 文件
安装
配置app.config
因为Nuget下载后配置的App.config文件汇报错,所以还需要修改下:
<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb" /> </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>
<system.data> <!-- NOTE: The extra "remove" element below is to prevent the design-time support components within EF6 from selecting the legacy ADO.NET provider for SQLite (i.e. the one without any EF6 support). It appears to only consider the first ADO.NET provider in the list within the resulting "app.config" or "web.config" file. --> <DbProviderFactories> <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> </DbProviderFactories> </system.data>
更多细节查看:
http://hintdesk.com/sqlite-with-entity-framework-code-first-and-migration/
https://stackoverflow.com/questions/21757843/system-data-sqlite-1-0-91-0-and-ef6-0-2?lq=1
Unfortunately, the EF6 provider implementation in System.Data.SQLite.EF6 doesn't currently support creating tables.
作者:旭东
出处:http://www.cnblogs.com/HQFZ
关于作者:专注于微软平台项目架构、管理和企业解决方案。现主要从事WinForm、ASP.NET、WPF、WCF、等方面的项目开发、架构、管理。如有问题或建议,请不吝指教!
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以联系我,非常感谢。
如果您该文觉得不错或者对你有帮助,请点下推荐,让更多的朋友看到,谢谢!