WhereColumns add check

This commit is contained in:
610262374@qq.com
2018-12-17 18:39:51 +08:00
parent b0aff94d24
commit 8a74acfbef
2 changed files with 13 additions and 0 deletions

View File

@@ -115,6 +115,10 @@ namespace OrmTest.Demo
.Where(p => p.SchoolId == SqlFunc.Subqueryable<Student>().Where(s => s.SchoolId == p.Id).Select(s => s.Id)).ExecuteCommand();
var t24 = db.Updateable(new Student() { }).WhereColumns(it=>it.CreateTime).ExecuteCommand();
var t25 = db.Updateable(new Student() { }).UpdateColumns(it=> new { it.Name,it.CreateTime}).WhereColumns(it => it.CreateTime).ExecuteCommand();
var t26 = db.Updateable(new List<Student>() { new Student() { }, new Student() { } }).UpdateColumns(it => new { it.Name, it.CreateTime }).WhereColumns(it => it.CreateTime).ExecuteCommand();
}
}
}

View File

@@ -24,6 +24,7 @@ namespace SqlSugar
public List<MappingColumn> MappingColumnList { get; set; }
private List<string> IgnoreColumnNameList { get; set; }
private List<string> WhereColumnList { get; set; }
private bool IsWhereColumns { get; set; }
private bool IsOffIdentity { get; set; }
private bool IsVersionValidation { get; set; }
public MappingTableList OldMappingTableList { get; set; }
@@ -153,6 +154,7 @@ namespace SqlSugar
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
{
this.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>();
@@ -394,6 +396,13 @@ namespace SqlSugar
private void PreToSql()
{
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();
if (this.IsWhereColumns) {
foreach (var pkName in UpdateBuilder.PrimaryKeys)
{
var isContains=this.UpdateBuilder.DbColumnInfoList.Select(it => it.DbColumnName.ToLower()).Contains(pkName.ToLower());
Check.Exception(isContains == false, "Use UpdateColumns().WhereColumn() ,UpdateColumns need {0}", pkName);
}
}
#region IgnoreColumns
if (this.Context.IgnoreColumns != null && this.Context.IgnoreColumns.Any())
{