Ejemplo n.º 1
0
 /// <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>());
     }
 }
Ejemplo n.º 2
0
 /// <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));
     }
 }
Ejemplo n.º 3
0
 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));
     }
 }
Ejemplo n.º 4
0
 /// <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));
     }
 }
Ejemplo n.º 5
0
        /// <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);
                }
            }
        }