mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Code optimization
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -199,6 +200,93 @@ namespace SqlSugar
|
||||
return methodCallExpressionArgs;
|
||||
}
|
||||
|
||||
protected void ResolveNewExpressions(ExpressionParameter parameter, int i, Expression item, string memberName)
|
||||
{
|
||||
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
else if (item is MethodCallExpression)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
}
|
||||
else if (item is MemberExpression || item is UnaryExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
this.Context.Result.CurrentParameter = parameter;
|
||||
this.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item is BinaryExpression)
|
||||
{
|
||||
if (this.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
this.Context.Result.CurrentParameter = parameter;
|
||||
this.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
this.Expression = item;
|
||||
parameter.CommonTempData = "simple";
|
||||
this.Start();
|
||||
parameter.CommonTempData = null;
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.TrimEnd();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
var shortName = parameter.CommonTempData;
|
||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||
foreach (var property in listProperties)
|
||||
{
|
||||
if (this.Context.IgnoreComumnList != null
|
||||
&& this.Context.IgnoreComumnList.Any(
|
||||
it => it.EntityName == item.Type.Name && it.PropertyName == property.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (property.PropertyType.IsClass())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var asName = "[" + item.Type.Name + "." + property.Name + "]";
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
this.Context.Result.Append(Context.GetAsString(asName, columnName, shortName.ObjToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Append(Context.GetAsString(asName, columnName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void AppendNot(object Value)
|
||||
{
|
||||
this.Context.Result.Append("NOT");
|
||||
|
@@ -98,89 +98,7 @@ namespace SqlSugar
|
||||
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
||||
var memberName = memberAssignment.Member.Name;
|
||||
var item = memberAssignment.Expression;
|
||||
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
else if (item is MethodCallExpression)
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
}
|
||||
else if (item is MemberExpression|| item is UnaryExpression)
|
||||
{
|
||||
if (base.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
base.Context.Result.CurrentParameter = parameter;
|
||||
base.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
parameter.IsAppendResult();
|
||||
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
base.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item is BinaryExpression)
|
||||
{
|
||||
if (base.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
base.Context.Result.CurrentParameter = parameter;
|
||||
base.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
base.Expression = item;
|
||||
parameter.CommonTempData = "simple";
|
||||
base.Start();
|
||||
parameter.CommonTempData = null;
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.TrimEnd();
|
||||
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
base.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
var shortName = parameter.CommonTempData;
|
||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||
foreach (var property in listProperties)
|
||||
{
|
||||
if (this.Context.IgnoreComumnList != null
|
||||
&& this.Context.IgnoreComumnList.Any(
|
||||
it => it.EntityName == item.Type.Name && it.PropertyName == property.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (property.PropertyType.IsClass())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var asName = item.Type.Name + "." + property.Name ;
|
||||
asName = Context.GetTranslationText(asName);
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
base.Context.Result.Append(Context.GetAsString(asName, columnName, shortName.ObjToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Append(Context.GetAsString(asName, columnName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
}
|
||||
ResolveNewExpressions(parameter, i, item, memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -50,88 +50,7 @@ namespace SqlSugar
|
||||
{
|
||||
string memberName = expression.Members[i].Name;
|
||||
++i;
|
||||
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
else if (item is MethodCallExpression) {
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
parameter.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
}
|
||||
else if (item is MemberExpression || item is UnaryExpression)
|
||||
{
|
||||
if (base.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
base.Context.Result.CurrentParameter = parameter;
|
||||
base.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
parameter.IsAppendResult();
|
||||
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
base.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item is BinaryExpression)
|
||||
{
|
||||
if (base.Context.Result.IsLockCurrentParameter == false)
|
||||
{
|
||||
base.Context.Result.CurrentParameter = parameter;
|
||||
base.Context.Result.IsLockCurrentParameter = true;
|
||||
parameter.IsAppendTempDate();
|
||||
base.Expression = item;
|
||||
parameter.CommonTempData = "simple";
|
||||
base.Start();
|
||||
parameter.CommonTempData = null;
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.TrimEnd();
|
||||
base.Context.Result.Append(base.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
base.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
else if (item.Type.IsClass())
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
var shortName = parameter.CommonTempData;
|
||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||
foreach (var property in listProperties)
|
||||
{
|
||||
if (this.Context.IgnoreComumnList != null
|
||||
&& this.Context.IgnoreComumnList.Any(
|
||||
it => it.EntityName == item.Type.Name && it.PropertyName == property.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (property.PropertyType.IsClass())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var asName = "[" + item.Type.Name + "." + property.Name + "]";
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
base.Context.Result.Append(Context.GetAsString(asName, columnName, shortName.ObjToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Append(Context.GetAsString(asName, columnName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
|
||||
}
|
||||
ResolveNewExpressions(parameter, i, item, memberName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user