sqlite ef6
Posted Red Cat
拿梦想做
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.database.sqlite异常(代码片段