예제 #1
0
 public async Task <T> SingleOrDefaultAsync <T>(string whereSql, dynamic param)
 {
     if (whereSql.TrimStart().ToLower().StartsWith("where", StringComparison.InvariantCulture))
     {
         whereSql = _SQLBuilder.BuildSelect(TypeMaper.GetTableName <T>(), TypeMaper.GetPropertiesName(typeof(T))).AppendSql(whereSql).ToSql();
     }
     return(await SqlMapper.QueryFirstOrDefaultAsync <T>(DBConnection, whereSql, param, DBTransaction, _Config.CommandTimeout));
 }
예제 #2
0
        public async Task <List <T> > BatchInsertAsync <T>(List <T> entities)
        {
            var type = typeof(T);
            var sql  = _SQLBuilder.BuildInsert(TypeMaper.GetTableName <T>(), TypeMaper.GetPropertiesName(type)).ToSql();

            await this.ExecuteNonQueryAsync(sql, entities);

            return(entities);
        }
예제 #3
0
        public async Task <T> SingleOrDefaultByIdAsync <T>(dynamic PrimaryKey)
        {
            var keyName = TypeMaper.GetSingleKeyName <T>();
            var sql     = _SQLBuilder.BuildSelect(TypeMaper.GetTableName <T>(), TypeMaper.GetPropertiesName(typeof(T))).Where().AppendColumnNameEqualsValue(keyName).ToSql();
            var param   = new DynamicParameters();

            param.Add(Adapter.DbParmChar + keyName, PrimaryKey);
            return(await SqlMapper.QuerySingleOrDefaultAsync <T>(DBConnection, sql, param, DBTransaction, _Config.CommandTimeout));
        }
예제 #4
0
        public async Task <List <T> > GetListAsync <T>(string whereSql, dynamic param)
        {
            if (whereSql.TrimStart().ToLower().StartsWith("where", StringComparison.InvariantCulture))
            {
                whereSql = _SQLBuilder.BuildSelect(TypeMaper.GetTableName <T>(), TypeMaper.GetPropertiesName(typeof(T))).AppendSql(whereSql).ToSql();
            }

            IEnumerable <T> result = await SqlMapper.QueryAsync <T>(DBConnection, whereSql, param, DBTransaction, _Config.CommandTimeout, CommandType.Text);

            return(result.ToList <T>());
        }
예제 #5
0
        public async Task <List <T> > GetAllAsync <T>()
        {
            var sql = _SQLBuilder.BuildSelect(TypeMaper.GetTableName <T>(), TypeMaper.GetPropertiesName(typeof(T))).ToSql();

            return((await DBConnection.QueryAsync <T>(sql, null, DBTransaction, _Config.CommandTimeout)).ToList());
        }