using FreeSql; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Core.DBManager; namespace WIDESEA_Core.FreeDB { public class FreeDB { private static IFreeSql DB; public IFreeSql DataBase { get => DB; } public FreeDB() { if (DB == null) { string coon = DBServerProvider.GetConnectionString(); DB = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.SqlServer, coon) .Build(); } } /// /// 插入数据 /// /// /// /// public int Add(T entity) where T : class { return DB.Insert(entity).ExecuteAffrows(); } /// /// 批量插入 /// /// /// /// public int AddRange(List entityList) where T : class { return DB.Insert(entityList).ExecuteAffrows(); } /// /// 删除 /// /// /// /// public int Remove(T entity) where T : class { return DB.Delete(entity).ExecuteAffrows(); } /// /// 更新(拓展方法) /// /// /// /// public IUpdate Update(T entity) where T : class { return DB.Update(entity).SetSource(entity); } /// /// 更新(拓展方法) /// /// /// public IUpdate Update() where T : class { return DB.Update(); } /// /// 查询 /// /// /// public ISelect Select() where T : class { return DB.Select(); } /// /// 事务(完整事务) /// /// public void Transaction(Action action) { DB.Transaction(action); } /// /// 事务(上下文事务) /// /// public void Context(Action action) { using (var db = DB.CreateDbContext()) { action(db); } } } }