mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
UpdateWhereColumns
This commit is contained in:
@@ -31,6 +31,7 @@ namespace SqlSugar
|
||||
public bool IsNoUpdateDefaultValue { get; set; }
|
||||
public List<string> PrimaryKeys { get; set; }
|
||||
public bool IsOffIdentity { get; set; }
|
||||
public bool IsWhereColumns { get; set; }
|
||||
|
||||
public virtual string SqlTemplate
|
||||
{
|
||||
@@ -253,6 +254,15 @@ namespace SqlSugar
|
||||
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
||||
}
|
||||
}
|
||||
if (PrimaryKeys.HasValue()&&IsWhereColumns)
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? " WHERE " : " AND ");
|
||||
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
|
||||
}
|
||||
}
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnsString, whereString);
|
||||
}
|
||||
|
||||
|
@@ -167,6 +167,7 @@ namespace SqlSugar
|
||||
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
this.IsWhereColumns = true;
|
||||
UpdateBuilder.IsWhereColumns = true;
|
||||
Check.Exception(UpdateParameterIsNull == true, "Updateable<T>().Updateable is error,Use Updateable(obj).WhereColumns");
|
||||
var whereColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
||||
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();
|
||||
|
Reference in New Issue
Block a user