Ejemplo n.º 1
0
        public async Task <int> UpdateAsync <T>(T entity)
        {
            var type            = typeof(T);
            var keyProperties   = TypeMaper.GetSingleKey <T>();
            var tableName       = TypeMaper.GetTableName <T>();
            var allProperties   = TypeMaper.GetProperties(type);
            var noKeyProperties = allProperties.Except(new List <PropertyInfo>()
            {
                keyProperties
            }).ToList();
            var sql = _SQLBuilder.BuildUpdate(tableName, noKeyProperties.Select(p => p.Name).ToList()).Where().AppendColumnNameEqualsValue(keyProperties.Name).ToSql();

            return(await ExecuteNonQueryAsync(sql.ToString(), entity));
        }
Ejemplo n.º 2
0
        public async Task <int> UpdateAsync <T>(T entity, string fields)
        {
            if (string.IsNullOrWhiteSpace(fields))
            {
                return(0);
            }
            var type          = typeof(T);
            var keyProperties = TypeMaper.GetSingleKey <T>();
            var tableName     = TypeMaper.GetTableName <T>();
            var allProperties = TypeMaper.GetProperties(type);

            var arrayfields = fields.ToLower().Split(',');

            allProperties = allProperties.Where(p => arrayfields.Contains(p.Name.ToLower())).ToList();
            var noKeyProperties = allProperties.Except(new List <PropertyInfo>()
            {
                keyProperties
            }).ToList();

            var sql = _SQLBuilder.BuildUpdate(tableName, noKeyProperties.Select(p => p.Name).ToList()).Where().AppendColumnNameEqualsValue(keyProperties.Name).ToSql();

            return(await ExecuteNonQueryAsync(sql.ToString(), entity));
        }