Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
11b4ebc77e
  1. BIN
      .vs/SqlSugar/v14/.suo
  2. 6
      OrmTest/Program.cs
  3. BIN
      OrmTest/bin/Debug/OrmTest.exe
  4. BIN
      OrmTest/bin/Debug/OrmTest.pdb
  5. BIN
      OrmTest/bin/Debug/SqlSugar.dll
  6. BIN
      OrmTest/bin/Debug/SqlSugar.pdb
  7. BIN
      OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache
  8. BIN
      OrmTest/obj/Debug/OrmTest.exe
  9. BIN
      OrmTest/obj/Debug/OrmTest.pdb
  10. 19
      SqlSugar/Expressions/ExpItems/MemberExpressionResolve.cs
  11. 81
      SqlSugar/Expressions/ExpressionContext.cs
  12. 0
      SqlSugar/ExpressionsToSql/ExpConst.cs
  13. 0
      SqlSugar/ExpressionsToSql/ExpInfo.cs
  14. 26
      SqlSugar/ExpressionsToSql/ExpItems/BaseResolve.cs
  15. 4
      SqlSugar/ExpressionsToSql/ExpItems/BinaryExpressionResolve.cs
  16. 2
      SqlSugar/ExpressionsToSql/ExpItems/BlockExpressionResolve.cs
  17. 2
      SqlSugar/ExpressionsToSql/ExpItems/ConditionalExpressionResolve.cs
  18. 2
      SqlSugar/ExpressionsToSql/ExpItems/ConstantExpressionResolve.cs
  19. 4
      SqlSugar/ExpressionsToSql/ExpItems/LambdaExpressionResolve.cs
  20. 33
      SqlSugar/ExpressionsToSql/ExpItems/MemberExpressionResolve.cs
  21. 2
      SqlSugar/ExpressionsToSql/ExpItems/MethodCallExpressionResolve.cs
  22. 2
      SqlSugar/ExpressionsToSql/ExpItems/UnaryExpressionResolve.cs
  23. 3
      SqlSugar/ExpressionsToSql/ExpResolveAccessory.cs
  24. 0
      SqlSugar/ExpressionsToSql/ExpTool.cs
  25. 45
      SqlSugar/ExpressionsToSql/ExpressionContext.cs
  26. 4
      SqlSugar/ExpressionsToSql/ExpressionParameter.cs
  27. 0
      SqlSugar/ExpressionsToSql/ResolveExpressType.cs
  28. 32
      SqlSugar/SqlSugar.csproj
  29. BIN
      SqlSugar/bin/Debug/SqlSugar.dll
  30. BIN
      SqlSugar/bin/Debug/SqlSugar.pdb
  31. 1
      SqlSugar/obj/Debug/SqlSugar.csproj.FileListAbsolute.txt
  32. BIN
      SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache
  33. BIN
      SqlSugar/obj/Debug/SqlSugar.dll
  34. BIN
      SqlSugar/obj/Debug/SqlSugar.pdb

BIN
.vs/SqlSugar/v14/.suo

Binary file not shown.

6
OrmTest/Program.cs

@ -15,10 +15,10 @@ namespace OrmTest
{
static void Main(string[] args)
{
Expression<Func<Student, bool>> exp = it => it.Id > 0;
Expression<Func<Student, bool>> exp = it => it.Name!="";
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.Single);
// var x = expContext.GetFiledName();
var xx = expContext.GetWhere();
var xx = expContext.ToString();
var b = DateTime.Now;
@ -26,7 +26,7 @@ namespace OrmTest
{
DbType = DbType.SqlServer,
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest",
EntityNamespace = "SqlSugar4XTest.Models",
EntityNamespace = "OrmTest.Models",
IsAutoCloseConnection = false
};
SqlSugarClient db = new SqlSugarClient(config);

BIN
OrmTest/bin/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/bin/Debug/OrmTest.pdb

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
OrmTest/bin/Debug/SqlSugar.pdb

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.exe

Binary file not shown.

BIN
OrmTest/obj/Debug/OrmTest.pdb

Binary file not shown.

19
SqlSugar/Expressions/ExpItems/MemberExpressionResolve.cs

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class MemberExpressionResolve:BaseResolve
{
public MemberExpressionResolve(Expression exp) : base(exp)
{
var isLeft = this.IsLeft;
this.IsLeft = null;
var isSingle=base.Context.IsSingle;
var expression = exp as MemberExpression;
}
}
}

81
SqlSugar/Expressions/ExpressionContext.cs

@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class ExpressionContext : ExpResolveAccessory
{
public ResolveExpressType Type { get; set; }
public Expression Expression { get; set; }
public bool IsSingle { get { return this.Type == ResolveExpressType.Single; } }
public ExpressionContext(Expression expression, ResolveExpressType type)
{
this.Type = type;
this.Expression = expression;
}
public string GetFiledName()
{
string reval = null;
LambdaExpression lambda = this.Expression as LambdaExpression;
var isConvet = lambda.Body.NodeType.IsIn(ExpressionType.Convert);
var isMember = lambda.Body.NodeType.IsIn(ExpressionType.MemberAccess);
if (!isConvet && !isMember)
throw new SqlSugarException(ErrorMessage.ExpFileldError);
try
{
if (isConvet && IsSingle)
{
var memberExpr = ((UnaryExpression)lambda.Body).Operand as MemberExpression;
reval = memberExpr.Member.Name;
}
else if (!isConvet && IsSingle)//isMember
{
reval = (lambda.Body as MemberExpression).Member.Name;
}
else if (isConvet && !IsSingle)
{
var memberExpr = ((UnaryExpression)lambda.Body).Operand as MemberExpression;
reval = memberExpr.ToString();
}
else if (!isConvet && !IsSingle)
{
reval = lambda.Body.ToString();
}
}
catch
{
throw new SqlSugarException(ErrorMessage.ExpFileldError);
}
return reval;
}
public string GetWhere()
{
BaseResolve resolve = new BaseResolve(this.Expression);
resolve.Context = this;
resolve.Start();
return resolve.SqlWhere;
}
public string GetSelect() { return ""; }
public List<SqlParameter> Parameters
{
get
{
return PubMethod.IsNullReturnNew(base._Parameters);
}
set
{
base._Parameters = value;
}
}
public int Index { get; set; }
}
}

0
SqlSugar/Expressions/ExpConst.cs → SqlSugar/ExpressionsToSql/ExpConst.cs

0
SqlSugar/Expressions/ExpInfo.cs → SqlSugar/ExpressionsToSql/ExpInfo.cs

26
SqlSugar/Expressions/ExpItems/BaseResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/BaseResolve.cs

@ -8,7 +8,6 @@ namespace SqlSugar
public class BaseResolve
{
protected Expression Expression { get; set; }
protected Expression BaseExpression { get; set; }
public ExpressionContext Context { get; set; }
public string SqlWhere { get; set; }
public bool IsFinished { get; set; }
@ -19,24 +18,31 @@ namespace SqlSugar
{
}
public BaseResolve(Expression expression)
public BaseResolve(ExpressionParameter parameter)
{
this.Expression = expression;
this.Expression = parameter.Expression;
this.Context = parameter.Context;
}
public BaseResolve Start()
{
this.Index++;
this.IsFinished = false;
this.BaseExpression = null;
Expression exp = this.Expression;
ExpressionParameter parameter = new ExpressionParameter()
{
Context = this.Context,
Expression = exp,
IsLeft = this.IsLeft,
BaseExpression=this.Expression
};
if (exp is LambdaExpression)
{
return new LambdaExpressionResolve(exp);
return new LambdaExpressionResolve(parameter);
}
else if (exp is BinaryExpression)
{
return new BinaryExpressionResolve(exp);
return new BinaryExpressionResolve(parameter);
}
else if (exp is BlockExpression)
{
@ -48,19 +54,19 @@ namespace SqlSugar
}
else if (exp is MethodCallExpression)
{
return new MethodCallExpressionResolve(exp);
return new MethodCallExpressionResolve(parameter);
}
else if (exp is ConstantExpression)
{
return new ConstantExpressionResolve(exp);
return new ConstantExpressionResolve(parameter);
}
else if (exp is MemberExpression)
{
return new MemberExpressionResolve(exp);
return new MemberExpressionResolve(parameter);
}
else if (exp is UnaryExpression)
{
return new UnaryExpressionResolve(exp);
return new UnaryExpressionResolve(parameter);
}
else if (exp != null && exp.NodeType.IsIn(ExpressionType.New, ExpressionType.NewArrayBounds, ExpressionType.NewArrayInit))
{

4
SqlSugar/Expressions/ExpItems/BinaryExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/BinaryExpressionResolve.cs

@ -7,10 +7,10 @@ namespace SqlSugar
{
public class BinaryExpressionResolve : BaseResolve
{
public BinaryExpressionResolve(Expression exp) : base(exp)
public BinaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
var expression = this.Expression as BinaryExpression;
base.BaseExpression = expression;
var baseExpression = parameter.Expression;
base.IsLeft = true;
base.Expression = expression.Left;
base.Start();

2
SqlSugar/Expressions/ExpItems/BlockExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/BlockExpressionResolve.cs

@ -7,7 +7,7 @@ namespace SqlSugar
{
public class BlockExpressionResolve:BaseResolve
{
public BlockExpressionResolve(Expression exp):base(exp)
public BlockExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
}

2
SqlSugar/Expressions/ExpItems/ConditionalExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/ConditionalExpressionResolve.cs

@ -7,7 +7,7 @@ namespace SqlSugar
{
public class ConditionalExpressionResolve:BaseResolve
{
public ConditionalExpressionResolve(Expression exp) : base(exp)
public ConditionalExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
}

2
SqlSugar/Expressions/ExpItems/ConstantExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/ConstantExpressionResolve.cs

@ -7,7 +7,7 @@ namespace SqlSugar
{
public class ConstantExpressionResolve:BaseResolve
{
public ConstantExpressionResolve(Expression exp) : base(exp)
public ConstantExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
}

4
SqlSugar/Expressions/ExpItems/LambdaExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/LambdaExpressionResolve.cs

@ -7,9 +7,9 @@ namespace SqlSugar
{
public class LambdaExpressionResolve : BaseResolve
{
public LambdaExpressionResolve(Expression exp) : base(exp)
public LambdaExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
LambdaExpression lambda = exp as LambdaExpression;
LambdaExpression lambda =base.Expression as LambdaExpression;
var expression = lambda.Body;
if (expression.NodeType == ExpressionType.MemberAccess)
{

33
SqlSugar/ExpressionsToSql/ExpItems/MemberExpressionResolve.cs

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class MemberExpressionResolve : BaseResolve
{
public MemberExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
var expression = base.Expression as MemberExpression;
var isLeft = this.IsLeft;
this.IsLeft = null;
var isSingle = base.Context.IsSingle;
string field = string.Empty;
field = isSingle ? expression.Member.Name : expression.Member.ToString();
base.IsFinished = true;
if (IsLeft == true)
{
base.SqlWhere += ExpTool.GetOperator(parameter.BaseExpression.NodeType);
}
else if (isLeft == false)
{
}
else
{
}
}
}
}

2
SqlSugar/Expressions/ExpItems/MethodCallExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/MethodCallExpressionResolve.cs

@ -7,7 +7,7 @@ namespace SqlSugar
{
public class MethodCallExpressionResolve:BaseResolve
{
public MethodCallExpressionResolve(Expression exp) : base(exp)
public MethodCallExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
}

2
SqlSugar/Expressions/ExpItems/UnaryExpressionResolve.cs → SqlSugar/ExpressionsToSql/ExpItems/UnaryExpressionResolve.cs

@ -7,7 +7,7 @@ namespace SqlSugar
{
public class UnaryExpressionResolve:BaseResolve
{
public UnaryExpressionResolve(Expression exp) : base(exp)
public UnaryExpressionResolve(ExpressionParameter parameter) : base(parameter)
{
}

3
SqlSugar/Expressions/ExpResolveAccessory.cs → SqlSugar/ExpressionsToSql/ExpResolveAccessory.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
@ -7,6 +8,6 @@ namespace SqlSugar
{
public class ExpResolveAccessory
{
protected List<SqlParameter> _Parameters { get; set; }
protected List<DbParameter> _Parameters { get; set; }
}
}

0
SqlSugar/Expressions/ExpTool.cs → SqlSugar/ExpressionsToSql/ExpTool.cs

45
SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class ExpressionContext : ExpResolveAccessory
{
public ResolveExpressType Type { get; set; }
public Expression Expression { get; set; }
public bool IsSingle { get { return this.Type == ResolveExpressType.Single; } }
public ExpressionContext(Expression expression, ResolveExpressType type)
{
this.Type = type;
this.Expression = expression;
}
public override string ToString()
{
BaseResolve resolve = new BaseResolve(new ExpressionParameter() { Expression=this.Expression, Context=this });
resolve.Start();
return resolve.SqlWhere;
}
public string GetSelect() { return ""; }
public List<DbParameter> Parameters
{
get
{
return PubMethod.IsNullReturnNew(base._Parameters);
}
set
{
base._Parameters = value;
}
}
public int Index { get; set; }
}
}

4
SqlSugar/Entities/ExpressionParameter.cs → SqlSugar/ExpressionsToSql/ExpressionParameter.cs

@ -9,6 +9,8 @@ namespace SqlSugar
public class ExpressionParameter
{
public Expression Expression { get; set; }
public SqlSugarClient DbContext { get; set; }
public ExpressionContext Context { get; set; }
public bool? IsLeft { get; set; }
public Expression BaseExpression { get; set; }
}
}

0
SqlSugar/Enum/ResolveExpressType.cs → SqlSugar/ExpressionsToSql/ResolveExpressType.cs

32
SqlSugar/SqlSugar.csproj

@ -97,7 +97,7 @@
<Compile Include="Entities\ConnectionConfig.cs" />
<Compile Include="Entities\DbColumnInfo.cs" />
<Compile Include="Entities\DbTableInfo.cs" />
<Compile Include="Entities\ExpressionParameter.cs" />
<Compile Include="ExpressionsToSql\ExpressionParameter.cs" />
<Compile Include="Entities\JoinQueryInfo.cs" />
<Compile Include="Entities\Mapping\MappingColumn.cs" />
<Compile Include="Entities\Mapping\MappingTable.cs" />
@ -106,21 +106,21 @@
<Compile Include="Enum\ApplyType.cs" />
<Compile Include="Enum\JoinType.cs" />
<Compile Include="Enum\OrderByType.cs" />
<Compile Include="Enum\ResolveExpressType.cs" />
<Compile Include="Expressions\ExpConst.cs" />
<Compile Include="Expressions\ExpInfo.cs" />
<Compile Include="Expressions\ExpItems\BaseResolve.cs" />
<Compile Include="Expressions\ExpItems\BinaryExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\BlockExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\ConditionalExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\ConstantExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\LambdaExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\MemberExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\MethodCallExpressionResolve.cs" />
<Compile Include="Expressions\ExpItems\UnaryExpressionResolve.cs" />
<Compile Include="Expressions\ExpResolveAccessory.cs" />
<Compile Include="Expressions\ExpressionContext.cs" />
<Compile Include="Expressions\ExpTool.cs" />
<Compile Include="ExpressionsToSql\ResolveExpressType.cs" />
<Compile Include="ExpressionsToSql\ExpConst.cs" />
<Compile Include="ExpressionsToSql\ExpInfo.cs" />
<Compile Include="ExpressionsToSql\ExpItems\BaseResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\BinaryExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\BlockExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\ConditionalExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\ConstantExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\LambdaExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\MemberExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\MethodCallExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpItems\UnaryExpressionResolve.cs" />
<Compile Include="ExpressionsToSql\ExpResolveAccessory.cs" />
<Compile Include="ExpressionsToSql\ExpressionContext.cs" />
<Compile Include="ExpressionsToSql\ExpTool.cs" />
<Compile Include="InstanceFactory.cs" />
<Compile Include="Interface\ICodeFirst.cs" />
<Compile Include="Interface\IDb.cs" />

BIN
SqlSugar/bin/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/bin/Debug/SqlSugar.pdb

Binary file not shown.

1
SqlSugar/obj/Debug/SqlSugar.csproj.FileListAbsolute.txt

@ -3,4 +3,3 @@ F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\SqlSugar\bin\Debug\SqlSugar.pdb
F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\SqlSugar\bin\Debug\Newtonsoft.Json.dll
F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\SqlSugar\obj\Debug\SqlSugar.dll
F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\SqlSugar\obj\Debug\SqlSugar.pdb
F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\SqlSugar\obj\Debug\SqlSugar.csprojResolveAssemblyReference.cache

BIN
SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.dll

Binary file not shown.

BIN
SqlSugar/obj/Debug/SqlSugar.pdb

Binary file not shown.
Loading…
Cancel
Save