sqllite3 的 “安装”不用说了,直接下载就用。
可以用Navicat for SQLite
当作客户端连接此数据库,直接操作。
上一个控制台代码,查询的,其他也一样。dapper操作。
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using Dapper;
using SQLiteDemo.Model;
namespace SQLiteDemo
{
public class SQLiteTool
{
public static string conn = @"Data Source=D:\green\sqlite\test.db;";
public static List<Student> GetAllStudents()
{
using (IDbConnection cnn = new SQLiteConnection(conn))
{
cnn.Open();
var output = cnn.Query<Student>("select * from student").ToList();
return output.ToList();
}
}
}
}
此处需要特别注意,这个 SQLiteConnection 是 System.Data.SQLite.SQLiteConnection
, 不是 Microsoft.Data.Sqlite.SqliteConnection
否则cnn.Open() 会报错。
报错内容:
You need to call SQLitePCL.raw.SetProvider(). If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init().”
上个Nuget
依赖图:
上图中,红框中的那个不需要,可删除,会造成迷惑。
上图中即为必要的,当然你可以可以不用NewtonSoft.Json
。
完毕,其余跟dapper操作mysql什么的就一样了。
上个客户端图:
上个git地址: https://gitee.com/festone/dot-net5-dapper-sqlite3