Browse Source

Optimized code

pull/32/head
sunkaixuan 2 years ago
parent
commit
066e676ce5
  1. 23
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Helper.cs
  2. 23
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs

23
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve_Helper.cs

@ -40,6 +40,29 @@ namespace SqlSugar
#endregion #endregion
#region Get Mehtod #region Get Mehtod
protected object GetMemberValue(object value, Expression exp)
{
if (exp is MemberExpression)
{
var member = (exp as MemberExpression);
var memberParent = member.Expression;
if (memberParent != null && this.Context?.SugarContext?.Context != null)
{
var entity = this.Context.SugarContext.Context.EntityMaintenance.GetEntityInfo(memberParent.Type);
var columnInfo = entity.Columns.FirstOrDefault(it => it.PropertyName == member.Member.Name);
if (columnInfo?.SqlParameterDbType is Type)
{
var type = columnInfo.SqlParameterDbType as Type;
var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
var obj = Activator.CreateInstance(type);
var p = ParameterConverter.Invoke(obj, new object[] { value, 100 + this.ContentIndex }) as SugarParameter;
value = p.Value;
}
}
}
return value;
}
private string GetAsName(Expression item, object shortName, PropertyInfo property) private string GetAsName(Expression item, object shortName, PropertyInfo property)
{ {
string asName; string asName;

23
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberConstExpressionResolve.cs

@ -35,27 +35,10 @@ namespace SqlSugar
private void Where(ExpressionParameter parameter, bool? isLeft, object value, ExpressionParameter baseParameter, bool isSetTempData) private void Where(ExpressionParameter parameter, bool? isLeft, object value, ExpressionParameter baseParameter, bool isSetTempData)
{ {
if (parameter.OppsiteExpression != null) if (parameter.OppsiteExpression != null)
{ {
var exp = ExpressionTool.RemoveConvert(parameter.OppsiteExpression); var exp = ExpressionTool.RemoveConvert(parameter.OppsiteExpression);
if (exp is MemberExpression) value = GetMemberValue(value, exp);
{
var member=(exp as MemberExpression);
var memberParent = member.Expression;
if (memberParent != null && this.Context?.SugarContext?.Context != null)
{
var entity = this.Context.SugarContext.Context.EntityMaintenance.GetEntityInfo(memberParent.Type);
var columnInfo = entity.Columns.FirstOrDefault(it => it.PropertyName == member.Member.Name);
if (columnInfo?.SqlParameterDbType is Type)
{
var type = columnInfo.SqlParameterDbType as Type;
var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
var obj = Activator.CreateInstance(type);
var p = ParameterConverter.Invoke(obj, new object[] { value, 100+this.ContentIndex }) as SugarParameter;
value = p.Value;
}
}
}
} }
if (isSetTempData) if (isSetTempData)
{ {
@ -66,7 +49,7 @@ namespace SqlSugar
AppendValue(parameter, isLeft, value); AppendValue(parameter, isLeft, value);
} }
} }
private object Select(ExpressionParameter parameter, object value) private object Select(ExpressionParameter parameter, object value)
{ {
if (value != null && value.GetType().IsEnum()) if (value != null && value.GetType().IsEnum())

Loading…
Cancel
Save