public static int Delete <T>(this SqlConnection connection, T entity, SqlTransaction trans = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; var sql = $"DELETE [{table}] WHERE Id=@Id"; return(connection.Execute(sql, new { entity.Id }, trans)); }
public static int Remove <T>(this SqlConnection connection, int[] ids, SqlTransaction trans = null) where T : BaseEntity, IRemoveAble { var table = MyContainer.Get(typeof(T)).Table; return(connection.Remove(table, ids, trans)); }
public static int Remove <T>(this SqlConnection connection, int[] ids, BaseAppUser user, SqlTransaction trans = null) where T : TraceEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Remove(table, ids, user, trans)); }
public static int Remove <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null) where T : BaseEntity, IRemoveAble { var table = MyContainer.Get(typeof(T)).Table; return(connection.Remove(table, entities.Select(e => e.Id).ToArray(), trans)); }
public static T Load <T>(this SqlConnection connection, int id, SqlTransaction trans = null, string table = "") { table = string.IsNullOrWhiteSpace(table) ? MyContainer.Get(typeof(T)).Table : table; var sql = $"SELECT TOP 1 * FROM [{table}] WHERE Id=@Id"; return(connection.QueryFirst(sql, new { Id = id }, trans)); }
public static int Delete <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; var sql = $"DELETE [{table}] WHERE Id IN @Ids"; return(connection.Execute(sql, new { Ids = entities.Select(e => e.Id) }, trans)); }
public static int Remove <T>(this SqlConnection connection, IEnumerable <T> entities, BaseAppUser user, SqlTransaction trans = null) where T : TraceEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Remove(table, entities.Select(e => e.Id).ToArray(), user, trans)); }
public static int Remove <T>(this SqlConnection connection, BaseAppUser user, MySearchUtil util, SqlTransaction trans = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Remove(table, user, util, trans)); }
public static T Load <T>(this SqlConnection connection, MySearchUtil util = null, SqlTransaction trans = null, string table = "") { util = util ?? new MySearchUtil(); table = string.IsNullOrWhiteSpace(table) ? MyContainer.Get(typeof(T)).Table : table; var where = util.GetWhere(); var orderBy = util.GetOrderBy(); var param = util.GetParam(); var sql = $"SELECT TOP 1 * FROM [{table}] WHERE {where} ORDER BY {orderBy}"; return(connection.QueryFirst(sql, param, trans)); }
public static int UpdateExclude <T>(this SqlConnection connection, string[] columns, T entity, SqlTransaction trans = null) where T : BaseEntity { var model = MyContainer.Get(typeof(T)); var table = model.Table; var allColumns = model.Properties.Where(p => p.PropertyName != "Id").Select(p => p.PropertyName); var cols = allColumns.Except(columns).ToList(); if (!cols.Any()) { throw new ArgumentNullException("未包含有效要更新的列"); } var sql = $"UPDATE [{table}] SET {string.Join(",", cols.Select(c => $"{c}=@{c}"))} WHERE Id=@Id"; return(connection.Execute(sql, entity, trans)); }
public static int Update <T>(this SqlConnection connection, KeyValuePairs kvs, MySearchUtil util, SqlTransaction trans = null) { var table = MyContainer.Get(typeof(T)).Table; return(connection.Update(table, kvs, util, trans)); }
public static int Update <T>(this SqlConnection connection, List <T> entities, SqlTransaction trans = null) where T : BaseEntity { var sql = MyContainer.Get(typeof(T)).UpdateSqlStatement; return(connection.Execute(sql, entities, trans)); }
public static int Update <T>(this SqlConnection connection, int[] ids, KeyValuePairs kvs, SqlTransaction tran = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Update(table, kvs, ids)); }
public static PageList <T> PageList <T>(this SqlConnection connection, int pageIndex, int pageSize, MySearchUtil util, string cols = "*") { var table = MyContainer.Get(typeof(T)).Table; return(connection.PageList <T>(table, pageIndex, pageSize, util, cols)); }
public static int Count <T>(this SqlConnection connection, MySearchUtil util = null, SqlTransaction trans = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Count(table, util, trans)); }
public static List <T> Fetch <T>(this SqlConnection connection, MySearchUtil util = null, string cols = "*", int top = 0) { var table = MyContainer.Get(typeof(T)).Table; return(connection.Fetch <T>(table, util, cols, top)); }
public static int Delete <T>(this SqlConnection connection, int id, SqlTransaction trans = null) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Delete(table, id, trans)); }
public static int Delete <T>(this SqlConnection connection, int[] ids) where T : BaseEntity { var table = MyContainer.Get(typeof(T)).Table; return(connection.Delete(table, ids)); }
public static int Delete <T>(this SqlConnection connection, MySearchUtil util = null) { var table = MyContainer.Get(typeof(T)).Table; return(connection.Delete(table, util)); }
/// <summary> /// 创建实体 /// </summary> /// <typeparam name="T">BaseEntity</typeparam> /// <param name="conn"></param> /// <param name="entity">要创建的实体</param> /// <param name="trans">事务</param> /// <returns>实体的Id</returns> public static int Create <T>(this SqlConnection conn, T entity, SqlTransaction trans = null) where T : BaseEntity { var sql = MyContainer.Get(typeof(T)).InsertSqlStatement; return(conn.ExecuteScalar <int>(sql, entity, trans)); }