Browse Source

Optimization EXP analysis

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f24f6e88cb
  1. 48
      Src/Asp.Net/SqlServerTest/Program.cs
  2. 24
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

48
Src/Asp.Net/SqlServerTest/Program.cs

@ -17,34 +17,34 @@ namespace OrmTest
{
static void Main(string[] args)
{
//// /***Unit Test***/
//new Select(1).Init();
//new Field(1).Init();
//new Where(1).Init();
//new Method(1).Init();
//new JoinQuery(1).Init();
//new SingleQuery(1).Init();
//new SelectQuery(1).Init();
//new AutoClose(1).Init();
//new Insert(1).Init();
//new Delete(1).Init();
//new Update(1).Init();
//new Mapping(1).Init();
//new DataTest(1).Init();
// /***Unit Test***/
new Select(1).Init();
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();
new JoinQuery(1).Init();
new SingleQuery(1).Init();
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
new Delete(1).Init();
new Update(1).Init();
new Mapping(1).Init();
new DataTest(1).Init();
///***Performance Test***/
//new SqlSugarPerformance(100).Select();
/***Performance Test***/
new SqlSugarPerformance(100).Select();
/***Demo***/
OrmTest.Demo.Query.Init();
//OrmTest.Demo.Insert.Init();
//OrmTest.Demo.Delete.Init();
//OrmTest.Demo.Update.Init();
//OrmTest.Demo.DbFirst.Init();
//OrmTest.Demo.JoinSql.Init();
//OrmTest.Demo.Filter.Init();
//OrmTest.Demo.ComplexModel.Init();
//OrmTest.Demo.CodeFirst.Init();
OrmTest.Demo.Insert.Init();
OrmTest.Demo.Delete.Init();
OrmTest.Demo.Update.Init();
OrmTest.Demo.DbFirst.Init();
OrmTest.Demo.JoinSql.Init();
OrmTest.Demo.Filter.Init();
OrmTest.Demo.ComplexModel.Init();
OrmTest.Demo.CodeFirst.Init();
}
}
}

24
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -70,10 +70,10 @@ namespace SqlSugar
var memberInfos = new Stack<MemberInfo>();
var fieldInfo = member as System.Reflection.FieldInfo;
object reval = null;
// "descend" toward's the root object reference:
MemberExpression memberExpr = null;
while (expression is MemberExpression)
{
var memberExpr = expression as MemberExpression;
memberExpr = expression as MemberExpression;
memberInfos.Push(memberExpr.Member);
if (memberExpr.Expression == null)
{
@ -106,18 +106,24 @@ namespace SqlSugar
var objProp = objReference.GetType().GetProperty(mi.Name);
if (objProp == null)
{
objReference = DynamicInvoke(expression,memberExpr);
}
else
{
objReference = objProp.GetValue(objReference, null);
}
objReference = objProp.GetValue(objReference, null);
}
else if (mi.MemberType == MemberTypes.Field)
{
var objField = objReference.GetType().GetField(mi.Name);
if (objField == null)
{
objReference = DynamicInvoke(expression, memberExpr);
}
else
{
objReference = objField.GetValue(objReference);
}
objReference = objField.GetValue(objReference);
}
}
reval = objReference;
@ -194,12 +200,12 @@ namespace SqlSugar
return reval;
}
public static object DynamicInvoke(Expression expression)
public static object DynamicInvoke(Expression expression,MemberExpression memberExpression=null)
{
object value = Expression.Lambda(expression).Compile().DynamicInvoke();
if (value != null && value.GetType().IsClass() && value.GetType() != ExpressionConst.StringType)
if (value != null && value.GetType().IsClass() && value.GetType() != ExpressionConst.StringType&& memberExpression!=null)
{
value = Expression.Lambda(expression).Compile().DynamicInvoke();
value = Expression.Lambda(memberExpression).Compile().DynamicInvoke();
}
return value;

Loading…
Cancel
Save