mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
WhereColumns add check
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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())
|
||||
{
|
||||
|
Reference in New Issue
Block a user