Skip to content

IUpdate<T1> UpdateColumns(String[] columns)建议增加属性名的判断 #95

Closed
@liuguiyou

Description

@liuguiyou
  freeSql.Update<ApplicationUser>()
  .SetSource(new ApplicationUser() { Id = 1, CreatedBy = 1 })
  .UpdateColumns(new string[] { nameof(ApplicationUser.CreatedBy) })

如果属性CreatedBy和对应的列名不一致更新不成功,建议相关代码加上属性名判断,nameof(属性名)这种用法更利于代码重构
改进的伪代码如下

public IUpdate<T1> UpdateColumns(string[] columns)
{
    var cols = columns.ToDictionary(a => a);
    _ignore.Clear();
    foreach (var col in _table.Columns.Values)
        if (cols.ContainsKey(col.Attribute.Name) == false && !cols.ContainsKey(col.CsName))
            _ignore.Add(col.Attribute.Name, true);
    return this;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions