/// <summary> /// 获取Model集合(没有Where条件) /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async Task <IEnumerable <T> > GetAllAsync <T>() where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return(await conn.GetAllAsync <T>()); } }
/// <summary> /// 获取Model-Key为string类型 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id"></param> /// <param name="transaction"></param> /// <param name="commandTimeout"></param> /// <returns></returns> public static async Task <T> GetAsync <T>(string id, IDbTransaction transaction = null, int?commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return(await conn.GetAsync <T>(id, transaction, commandTimeout)); } }
public static async Task <bool> DeleteAsync <T>(T model, IDbTransaction transaction = null, int?commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return(await conn.DeleteAsync <T>(model, transaction, commandTimeout)); } }
/// <summary> /// 增删改系 /// </summary> /// <param name="sql"></param> /// <param name="param"></param> /// <param name="transaction"></param> /// <param name="commandTimeout"></param> /// <param name="commandType"></param> /// <returns></returns> public static async Task <int> ExecuteAsync(string sql, object param = null, IDbTransaction transaction = null, int?commandTimeout = default(int?), CommandType?commandType = default(CommandType?)) { using (var conn = ConnFactory.GetConnection()) { return(await conn.ExecuteAsync(sql, param, transaction, commandTimeout, commandType)); } }
/// <summary> /// 更新一个Model /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <param name="transaction"></param> /// <param name="commandTimeout"></param> /// <returns></returns> public static async Task <T> UpdateAsync <T>(T model, IDbTransaction transaction = null, int?commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { bool b = await conn.UpdateAsync <T>(model, transaction, commandTimeout); if (b) { return(model); } else { return(null); } } }