UpdateColumns BUG

This commit is contained in:
sunkaixuan
2019-01-01 21:17:51 +08:00
parent 1352660437
commit ccb4622202
4 changed files with 67 additions and 35 deletions

View File

@@ -119,6 +119,15 @@ namespace OrmTest.Demo
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();
db.Updateable<Student>().UpdateColumns(it => new Student { SchoolId = GeneratePassword(2, 1), Name =it.Name+1, CreateTime = DateTime.Now.AddDays(1) }).Where(it => it.Id == 1).ExecuteCommand();
}
private static int GeneratePassword(int v1, int v2)
{
return 1;
}
}
}

View File

@@ -445,5 +445,38 @@ namespace SqlSugar
Check.ThrowNotSupportedException(item.GetType().Name);
}
}
protected static Dictionary<string, string> MethodMapping = new Dictionary<string, string>() {
{ "ToString","ToString"},
{ "ToInt32","ToInt32"},
{ "ToInt16","ToInt32"},
{ "ToInt64","ToInt64"},
{ "ToDecimal","ToDecimal"},
{ "ToDateTime","ToDate"},
{ "ToBoolean","ToBool"},
{ "ToDouble","ToDouble"},
{ "Length","Length"},
{ "Replace","Replace"},
{ "Contains","Contains"},
{ "ContainsArray","ContainsArray"},
{ "EndsWith","EndsWith"},
{ "StartsWith","StartsWith"},
{ "HasValue","HasValue"},
{ "Trim","Trim"},
{ "Equals","Equals"},
{ "ToLower","ToLower"},
{ "ToUpper","ToUpper"},
{ "Substring","Substring"},
{ "DateAdd","DateAdd"}
};
protected static Dictionary<string, DateType> MethodTimeMapping = new Dictionary<string, DateType>() {
{ "AddYears",DateType.Year},
{ "AddMonths",DateType.Month},
{ "AddDays",DateType.Day},
{ "AddHours",DateType.Hour},
{ "AddMinutes",DateType.Minute},
{ "AddSeconds",DateType.Second},
{ "AddMilliseconds",DateType.Millisecond}
};
}
}

View File

@@ -61,7 +61,17 @@ namespace SqlSugar
{
if (item is UnaryExpression)
item = (item as UnaryExpression).Operand;
MethodCall(parameter, memberName, item);
var callMethod = item as MethodCallExpression;
if (MethodTimeMapping.Any(it => it.Key == callMethod.Method.Name) || MethodMapping.Any(it=>it.Key==callMethod.Method.Name)||IsExtMethod(callMethod.Method.Name)||IsSubMethod(callMethod)|| callMethod.Method.DeclaringType.FullName.StartsWith(UtilConstants.AssemblyName+UtilConstants.Dot))
{
MethodCall(parameter, memberName, item);
}
else
{
var paramterValue = ExpressionTool.DynamicInvoke(item);
string parameterName = AppendParameter(paramterValue);
this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
}
}
else if (IsConst(item))
{
@@ -147,5 +157,19 @@ namespace SqlSugar
{
return SubTools.SubItemsConst.Any(it =>express.Object != null && express.Object.Type.Name == "Subqueryable`1");
}
private bool IsExtMethod(string methodName)
{
if (this.Context.SqlFuncServices == null) return false;
return this.Context.SqlFuncServices.Select(it => it.UniqueMethodName).Contains(methodName);
}
private bool CheckMethod(MethodCallExpression expression)
{
if (IsExtMethod(expression.Method.Name))
return true;
if (expression.Method.ReflectedType().FullName != ExpressionConst.SqlFuncFullName)
return false;
else
return true;
}
}
}

View File

@@ -513,40 +513,6 @@ namespace SqlSugar
return null;
}
private static Dictionary<string, string> MethodMapping = new Dictionary<string, string>() {
{ "ToString","ToString"},
{ "ToInt32","ToInt32"},
{ "ToInt16","ToInt32"},
{ "ToInt64","ToInt64"},
{ "ToDecimal","ToDecimal"},
{ "ToDateTime","ToDate"},
{ "ToBoolean","ToBool"},
{ "ToDouble","ToDouble"},
{ "Length","Length"},
{ "Replace","Replace"},
{ "Contains","Contains"},
{ "ContainsArray","ContainsArray"},
{ "EndsWith","EndsWith"},
{ "StartsWith","StartsWith"},
{ "HasValue","HasValue"},
{ "Trim","Trim"},
{ "Equals","Equals"},
{ "ToLower","ToLower"},
{ "ToUpper","ToUpper"},
{ "Substring","Substring"},
{ "DateAdd","DateAdd"}
};
private static Dictionary<string, DateType> MethodTimeMapping = new Dictionary<string, DateType>() {
{ "AddYears",DateType.Year},
{ "AddMonths",DateType.Month},
{ "AddDays",DateType.Day},
{ "AddHours",DateType.Hour},
{ "AddMinutes",DateType.Minute},
{ "AddSeconds",DateType.Second},
{ "AddMilliseconds",DateType.Millisecond}
};
private bool IsContainsArray(MethodCallExpression express, string methodName, bool isValidNativeMethod)
{
return !isValidNativeMethod && express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic") && methodName == "Contains";