sqlite ef6
参考文章:
http://www.cnblogs.com/adswads/p/3808549.html
用NUGET 引用 System.Data.SQLite.EF6 app.config 会有默认配置 其中有部分不对.不知道为什么
错误的Config
绿色不需要的虽然本身就是错的.
invariantName是SQLite type后面用了SqlProviderServices 正确的应该是SQLiteProviderServices
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SQLiteProviderServices, System.Data.SQLite.EF6" />-->
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SqlProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
正确的providers
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
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"/>
总之有点凌乱.
备忘一个代码.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder(this.Database.Connection.ConnectionString);
string path = AppDomain.CurrentDomain.BaseDirectory + connstr.DataSource;
System.IO.FileInfo fi = new System.IO.FileInfo(path);
if (System.IO.File.Exists(fi.FullName) == false)
{
if (System.IO.Directory.Exists(fi.DirectoryName) == false)
{
System.IO.Directory.CreateDirectory(fi.DirectoryName);
}
SQLiteConnection.CreateFile(fi.FullName); connstr.DataSource = path;
//connstr.Password = "admin";//设置密码,SQLite ADO.NET实现了数据库密码保护
using (SQLiteConnection conn = new SQLiteConnection(connstr.ConnectionString))
{
string sql = @" CREATE TABLE User (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Name varchar (20),
Time timestamp,
Data blob,
Val real,
TestE int);";
conn.Open();
SQLiteCommand cmd = new SQLiteCommand(sql, conn);
cmd.ExecuteNonQuery();
}
}
//添加创建代码
//modelBuilder.Configurations.Add(new Blog());
}
sqlite ef6的更多相关文章
- 关于Visio Studio 2012使用Nuget获取Sqlite驱动包报错:“System.Data.SQLite.EF6”的架构版本与 NuGet 的版本 2.0.30625.9003 不兼容
背景 笔者的VS2012版本比较老旧,是几年以前下载的.平时添加三方包和驱动包都是手动添加.后来了解到有Nuget这个工具,如获至宝.可是在使用过程中却出了不少问题. 最初,笔者尝试使用Nuget添加 ...
- Sqlite EF6注册
在EF6使用Sqlite的时候.Sqlite需要安装sqlite-netFx40-setup-bundle-x64-2010-1.0.97.0.exe.我不想在项目发布的时候,安装的时候执行该程序,于 ...
- sqlite ef6 踩坑
调试的时候配置写如下,这样写是没有问题的但是在实际环境中有问题,因为EF路径找不到.会提示错误:The underlying provider failed on open <connectio ...
- 【原创】sqlite ef6 踩坑
调试的时候配置写如下,这样写是没有问题的但是在实际环境中有问题,因为EF路径找不到.会提示错误:The underlying provider failed on open <connectio ...
- Web重温系列(二):SQLite+EF6实现本地化存储
本来我们的产品有着复杂的层次结构,作为客户端的C# WinForm是不操作数据库的.但是最近有个需求,需要将数据本地保存.可选的方案很多,比如文本文件或者XML序列化和反序列化,或者如access.d ...
- System.Data.SQLite.EF6
2015.1.21 到目前为止这个破玩意不支持code first 建数据库 建表 代替方案 SQL Server Compact -------------------------------- ...
- EF6 在 SQLite中使用备忘
== 菜鸟级选手试验在EF6中使用Sqlite,零EF基础,少量Sqlite基础.经过断断续续的很长时间 - _ -! >>连接 1. 安装 使用目前最新版本EF6.1,Sqlite1.0 ...
- Visual Studio 2015使用EF6的CodeFirstFromDB模式操作Sqlite数据库时Provider问题
传送门 什么是CodeFristFromDB 问题:查询数据是遇到 “/”应用程序中的服务器错误. No Entity Framework provider found for the ADO.NET ...
- Visual Studio 2015使用EF6的DBFirst模式操作Sqlite数据库
什么是DBFirst 1:到官方下载并安装32位驱动(如果你是旧版的驱动,卸载掉,然后下载最新版的,否则操作数据时会出现异常) 2:通过Nuget获取System.Data.SQLite(会默认把下面 ...
随机推荐
- HDoj-1042 大数阶乘
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- 做ppt经常使用站点
推荐一下做PPT经常使用的站点 一.字体 http://font.chinaz.com 二.ppt模板:演界网 三.图标 http://www.easyicon.net/
- Ant 给project打包
写了一段主要的war打包.编译文件复制的 ant 配置文件 xml <?xml version="1.0" encoding="utf-8"? > ...
- Leetcode 高精度 Plus One
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Plus One Total Accepted: 17614 Total Submissio ...
- 巧用CAS解决数据一致性问题
缘起:在高并发的分布式环境下,对于数据的查询与修改容易引发一致性问题,本文将分享一种非常简单但有效的优化方法. 一.业务场景 业务场景为,购买商品的过程要对余额进行查询与修改,大致的业务流程如下: ( ...
- 项目启动时候spring是如何加载和实例化各类的
1.对于注解为默认的,也就是@score不写的,默认是单例的类,这些类在项目启动的时候会依次被加载并被实例化.默认调用的是无参数的构造器. 2.而对于注解是prototype类型的,即@Scope(& ...
- Intellij IDEA 使用小结
快捷键 核心快捷键 IntelliJ IDEA 作为一个以快捷键为中心的 IDE,为大多数操作建议了键盘快捷键.在这个主题中,您可以找到最不可缺少的列表,使 IntelliJ IDEA 轻松实现第一步 ...
- javascript 面向对象设计之 Function 普通类
var test = "Class01"; function Class01(privateValue, publicValue) { var _this = this; if ( ...
- Oracle索引详解
Oracle索引详解(二) --索引分类 Oracle 提供了大量索引选项.知道在给定条件下使用哪个选项对于一个程序的性能来说非常重要.一个错误的选择可能会引发死锁,并导致数据库性能急剧下降或进程 ...
- Error Running Git Empty git --version output:IDEA关联GitHub时出现这个错误
刚刚学习使用idea中,想要把自己的项目上传到github,遇到这样一个问题,先记录下来,到时候解决了在把方法贴出来. ---------------------------------------- ...