Update WhereColumns

This commit is contained in:
sunkaixuna
2021-04-22 12:47:08 +08:00
parent 634864e77e
commit ca3770e8cb
2 changed files with 17 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ namespace SqlSugar
public DiffLogModel diffModel { get; set; } public DiffLogModel diffModel { get; set; }
private Action RemoveCacheFunc { get; set; } private Action RemoveCacheFunc { get; set; }
private int SetColumnsIndex { get; set; } private int SetColumnsIndex { get; set; }
private List<DbColumnInfo> columns { get; set; }
#endregion #endregion
#region Core #region Core
@@ -207,6 +208,7 @@ namespace SqlSugar
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>(); if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
foreach (var item in whereColumns) foreach (var item in whereColumns)
{ {
_WhereColumn(item);
this.WhereColumnList.Add(item); this.WhereColumnList.Add(item);
} }
return this; return this;
@@ -216,15 +218,18 @@ namespace SqlSugar
ThrowUpdateByExpression(); ThrowUpdateByExpression();
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>(); if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
_WhereColumn(columnName);
this.WhereColumnList.Add(columnName); this.WhereColumnList.Add(columnName);
return this; return this;
} }
public IUpdateable<T> WhereColumns(string[] columnNames) public IUpdateable<T> WhereColumns(string[] columnNames)
{ {
ThrowUpdateByExpression(); ThrowUpdateByExpression();
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>(); if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
foreach (var columnName in columnNames) foreach (var columnName in columnNames)
{ {
_WhereColumn(columnName);
this.WhereColumnList.Add(columnName); this.WhereColumnList.Add(columnName);
} }
return this; return this;
@@ -388,6 +393,16 @@ namespace SqlSugar
Before(sql); Before(sql);
return sql; return sql;
} }
private void _WhereColumn(string columnName)
{
var columnInfos = columns.Where(it => it.DbColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase) || it.PropertyName.Equals(columnName, StringComparison.OrdinalIgnoreCase)).ToList();
if (!this.UpdateBuilder.DbColumnInfoList.Any(y => y.DbColumnName == columnInfos.First().DbColumnName))
{
this.UpdateBuilder.DbColumnInfoList.AddRange(columnInfos);
}
}
private void AutoRemoveDataCache() private void AutoRemoveDataCache()
{ {
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings; var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
@@ -424,6 +439,7 @@ namespace SqlSugar
} }
++i; ++i;
} }
this.columns = this.UpdateBuilder.DbColumnInfoList;
} }
private void CheckTranscodeing(bool checkIsJson = true) private void CheckTranscodeing(bool checkIsJson = true)
{ {

View File

@@ -42,7 +42,7 @@ namespace SqlSugar
/// <returns></returns> /// <returns></returns>
IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns); IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns);
IUpdateable<T> WhereColumns(string columnName); IUpdateable<T> WhereColumns(string columnName);
IUpdateable<T> WhereColumns(string [] columnNames); IUpdateable<T> WhereColumns(params string [] columnNames);
/// <summary> /// <summary>
/// .UpdateColumns(it=>new{ it.Name,it.Price}) /// .UpdateColumns(it=>new{ it.Name,it.Price})