/// <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));
     }
 }
 /// <summary>
 /// 插入一个Model
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <param name="transaction"></param>
 /// <param name="commandTimeout"></param>
 /// <param name="sqlAdapter"></param>
 /// <returns></returns>
 public static async Task <int> InsertAsync <T>(T model, IDbTransaction transaction = null, int?commandTimeout = null) where T : class, new()
 {
     using (var conn = ConnFactory.GetConnection())
     {
         return(await conn.InsertAsync <T>(model, transaction, commandTimeout));
     }
 }
Exemple #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())
            {
                await conn.OpenAsync();

                return(await conn.ExecuteAsync(sql, param, transaction, commandTimeout, commandType));
            }
        }
        /// <summary>
        /// 更新一个Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="entityToUpdate"></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);
                }
            }
        }