using System; using System.Collections.Generic; using System.Linq.Expressions; namespace Mtxfw.Utility.DataAccess { /// /// 插入类 /// public partial class Sql : DbHelperSqlSugar { /// /// 插入一条记录 /// /// 实体类名称 /// 实体类 /// 插入并返回自增列 public int Insert(T entity) where T : class, new() { return Db.Insertable(entity).ExecuteReturnIdentity(); } /// /// 批量插入 /// /// 实体类名称 /// 实体类集合 /// 插入并返回受影响行数 public int Insert(List entitys) where T : class, new() { return Db.Insertable(entitys.ToArray()).ExecuteCommand(); } /// /// 批量插入 /// /// 实体类名称 /// 实体类集合 /// 插入并返回受影响行数 public int Insert(Dictionary dt) where T : class, new() { return Db.Insertable(dt).ExecuteCommand(); } /// /// 只插入指定列数据 /// /// 实体类名称 /// 实体类 /// 插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId /// public int InsertColumns(T entity, Expression> predicate) where T : class, new() { return Db.Insertable(entity).InsertColumns(predicate).ExecuteReturnIdentity(); } /// /// 只插入指定列数据(批量插入) /// /// 实体类名称 /// 实体类集合 /// 插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId /// public int InsertColumns(List entitys, Expression> predicate) where T : class, new() { return Db.Insertable(entitys.ToArray()).InsertColumns(predicate).ExecuteReturnIdentity(); } /// /// 不插入指定列数据 /// /// 实体类名称 /// 实体类 /// 插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId /// public int InsertIgnoreColumns(T entity, Expression> predicate) where T : class, new() { return Db.Insertable(entity).IgnoreColumns(predicate).ExecuteReturnIdentity(); } /// /// 不插入指定列数据(批量插入) /// /// 实体类名称 /// 实体类集合 /// /// 插入的指定列 -> it => new { it.Name, it.SchoolId }, 只插入列 Name和SchoolId /// 或者 it => it == "Name" || it == "TestId" /// /// public int InsertIgnoreColumns(List entitys, Expression> predicate) where T : class, new() { return Db.Insertable(entitys.ToArray()).IgnoreColumns(predicate).ExecuteReturnIdentity(); } /// /// 插入一列数据 /// public int InsertField(Dictionary dic) where T : class, new() { return Db.Insertable(dic).ExecuteReturnIdentity(); } } }