你不需要做任何神奇的事情。只需添加:
using Dapper;
并在打开的SqliteConnection
上运行查询
cnn.Query("select 'hello world' from Table")
这是一个带有内存数据库的完整工作示例。需要C#8.0。
using System;
using System.Data.SQLite;
using Dapper;
namespace First
{
// dotnet add package System.Data.SQLite.Core
// dotnet add package Dapper
class Program
{
static void Main(string[] args)
{
string cs = "Data Source=:memory:";
using var con = new SQLiteConnection(cs);
con.Open();
var res = con.QueryFirst("select SQLITE_VERSION() AS Version");
Console.WriteLine(res.Version);
}
}
}
运行示例:
$ dotnet run
3.30.1