首页 > 代码库 > sqlite ef6
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。