Nuget 安装以下程序包
1.SqlSugarCore
2.Microsoft.Data.Sqlite.Core
3.SQLitePCLRaw.bundle_e_sqlcipher
using Microsoft.Data.Sqlite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTest
{
///
/// Sqlsugar测试
///
[TestClass]
public class SqlsugarTest
{
///
/// 测试创建数据库
///
[TestMethod]
public void TestCreateSqliteDB()
{
try
{
//生成连接字符串
var connectionString = new SqliteConnectionStringBuilder("DataSource=C:/Users/hongz/Desktop/test.db;")
{
Mode = SqliteOpenMode.ReadWrite,
Password = "123456"
}.ToString();
//使用Sqlsugar连接Sqlite
using (SqlSugarClient client = new SqlSugarClient(
new ConnectionConfig()
{
ConnectionString = connectionString,
IsAutoCloseConnection = true,
DbType = DbType.Sqlite,
}))
{
client.Open();
List lt = client.Queryable().ToList();
//测试断言
Assert.IsTrue(lt.Count == 1);
}
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
//throw;
}
}
}
///
/// 临时测试实体表
///
class abc
{
public string a1 { get; set; }
}
}
本Demo仅展示Sqlsugar连接加密Sqlite部分,Sqlsugar IOC 等请自行查询



