UpdateWhereColumns

This commit is contained in:
610262374@qq.com
2019-06-09 21:19:49 +08:00
parent 51af495f22
commit d58c12d3b1
2 changed files with 11 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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>();