diff --git a/.vs/SqlSugar/v14/.suo b/.vs/SqlSugar/v14/.suo index bbba319e6..c060189f8 100644 Binary files a/.vs/SqlSugar/v14/.suo and b/.vs/SqlSugar/v14/.suo differ diff --git a/OrmTest/Program.cs b/OrmTest/Program.cs index 4bfc4c301..39223ce4e 100644 --- a/OrmTest/Program.cs +++ b/OrmTest/Program.cs @@ -15,10 +15,10 @@ namespace OrmTest { static void Main(string[] args) { - Expression> exp = it => it.Id > 0; + Expression> 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); diff --git a/OrmTest/bin/Debug/OrmTest.exe b/OrmTest/bin/Debug/OrmTest.exe index b26492bbb..03419f8d7 100644 Binary files a/OrmTest/bin/Debug/OrmTest.exe and b/OrmTest/bin/Debug/OrmTest.exe differ diff --git a/OrmTest/bin/Debug/OrmTest.pdb b/OrmTest/bin/Debug/OrmTest.pdb index a566fe9e5..e11c0c46e 100644 Binary files a/OrmTest/bin/Debug/OrmTest.pdb and b/OrmTest/bin/Debug/OrmTest.pdb differ diff --git a/OrmTest/bin/Debug/SqlSugar.dll b/OrmTest/bin/Debug/SqlSugar.dll index e05646c2f..962751266 100644 Binary files a/OrmTest/bin/Debug/SqlSugar.dll and b/OrmTest/bin/Debug/SqlSugar.dll differ diff --git a/OrmTest/bin/Debug/SqlSugar.pdb b/OrmTest/bin/Debug/SqlSugar.pdb index 6aab39ccc..fa6041745 100644 Binary files a/OrmTest/bin/Debug/SqlSugar.pdb and b/OrmTest/bin/Debug/SqlSugar.pdb differ diff --git a/OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache b/OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache index e275a6b98..1bc101d59 100644 Binary files a/OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache and b/OrmTest/obj/Debug/OrmTest.csprojResolveAssemblyReference.cache differ diff --git a/OrmTest/obj/Debug/OrmTest.exe b/OrmTest/obj/Debug/OrmTest.exe index b26492bbb..03419f8d7 100644 Binary files a/OrmTest/obj/Debug/OrmTest.exe and b/OrmTest/obj/Debug/OrmTest.exe differ diff --git a/OrmTest/obj/Debug/OrmTest.pdb b/OrmTest/obj/Debug/OrmTest.pdb index a566fe9e5..e11c0c46e 100644 Binary files a/OrmTest/obj/Debug/OrmTest.pdb and b/OrmTest/obj/Debug/OrmTest.pdb differ diff --git a/SqlSugar/Expressions/ExpItems/MemberExpressionResolve.cs b/SqlSugar/Expressions/ExpItems/MemberExpressionResolve.cs deleted file mode 100644 index 2bb8c8ef8..000000000 --- a/SqlSugar/Expressions/ExpItems/MemberExpressionResolve.cs +++ /dev/null @@ -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; - } - } -} diff --git a/SqlSugar/Expressions/ExpressionContext.cs b/SqlSugar/Expressions/ExpressionContext.cs deleted file mode 100644 index e8dc7b4e2..000000000 --- a/SqlSugar/Expressions/ExpressionContext.cs +++ /dev/null @@ -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 Parameters - { - get - { - return PubMethod.IsNullReturnNew(base._Parameters); - } - set - { - base._Parameters = value; - } - } - - public int Index { get; set; } - } -} diff --git a/SqlSugar/Expressions/ExpConst.cs b/SqlSugar/ExpressionsToSql/ExpConst.cs similarity index 100% rename from SqlSugar/Expressions/ExpConst.cs rename to SqlSugar/ExpressionsToSql/ExpConst.cs diff --git a/SqlSugar/Expressions/ExpInfo.cs b/SqlSugar/ExpressionsToSql/ExpInfo.cs similarity index 100% rename from SqlSugar/Expressions/ExpInfo.cs rename to SqlSugar/ExpressionsToSql/ExpInfo.cs diff --git a/SqlSugar/Expressions/ExpItems/BaseResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/BaseResolve.cs similarity index 71% rename from SqlSugar/Expressions/ExpItems/BaseResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/BaseResolve.cs index 48c173263..e21c82d9b 100644 --- a/SqlSugar/Expressions/ExpItems/BaseResolve.cs +++ b/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)) { diff --git a/SqlSugar/Expressions/ExpItems/BinaryExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/BinaryExpressionResolve.cs similarity index 79% rename from SqlSugar/Expressions/ExpItems/BinaryExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/BinaryExpressionResolve.cs index 41bb6148e..a54ed3d1f 100644 --- a/SqlSugar/Expressions/ExpItems/BinaryExpressionResolve.cs +++ b/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(); diff --git a/SqlSugar/Expressions/ExpItems/BlockExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/BlockExpressionResolve.cs similarity index 72% rename from SqlSugar/Expressions/ExpItems/BlockExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/BlockExpressionResolve.cs index 15537f093..1c35ed96a 100644 --- a/SqlSugar/Expressions/ExpItems/BlockExpressionResolve.cs +++ b/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) { } diff --git a/SqlSugar/Expressions/ExpItems/ConditionalExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/ConditionalExpressionResolve.cs similarity index 71% rename from SqlSugar/Expressions/ExpItems/ConditionalExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/ConditionalExpressionResolve.cs index bd32490d8..4f1719e2a 100644 --- a/SqlSugar/Expressions/ExpItems/ConditionalExpressionResolve.cs +++ b/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) { } diff --git a/SqlSugar/Expressions/ExpItems/ConstantExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/ConstantExpressionResolve.cs similarity index 71% rename from SqlSugar/Expressions/ExpItems/ConstantExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/ConstantExpressionResolve.cs index 39ad41e61..c47c41eee 100644 --- a/SqlSugar/Expressions/ExpItems/ConstantExpressionResolve.cs +++ b/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) { } diff --git a/SqlSugar/Expressions/ExpItems/LambdaExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/LambdaExpressionResolve.cs similarity index 77% rename from SqlSugar/Expressions/ExpItems/LambdaExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/LambdaExpressionResolve.cs index c226c5354..27eeaf141 100644 --- a/SqlSugar/Expressions/ExpItems/LambdaExpressionResolve.cs +++ b/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) { diff --git a/SqlSugar/ExpressionsToSql/ExpItems/MemberExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/MemberExpressionResolve.cs new file mode 100644 index 000000000..914b5ee7d --- /dev/null +++ b/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 + { + + } + } + } +} diff --git a/SqlSugar/Expressions/ExpItems/MethodCallExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/MethodCallExpressionResolve.cs similarity index 71% rename from SqlSugar/Expressions/ExpItems/MethodCallExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/MethodCallExpressionResolve.cs index 3dbb40036..4b0a0afcd 100644 --- a/SqlSugar/Expressions/ExpItems/MethodCallExpressionResolve.cs +++ b/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) { } diff --git a/SqlSugar/Expressions/ExpItems/UnaryExpressionResolve.cs b/SqlSugar/ExpressionsToSql/ExpItems/UnaryExpressionResolve.cs similarity index 72% rename from SqlSugar/Expressions/ExpItems/UnaryExpressionResolve.cs rename to SqlSugar/ExpressionsToSql/ExpItems/UnaryExpressionResolve.cs index 2631f1a89..32ef94992 100644 --- a/SqlSugar/Expressions/ExpItems/UnaryExpressionResolve.cs +++ b/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) { } diff --git a/SqlSugar/Expressions/ExpResolveAccessory.cs b/SqlSugar/ExpressionsToSql/ExpResolveAccessory.cs similarity index 68% rename from SqlSugar/Expressions/ExpResolveAccessory.cs rename to SqlSugar/ExpressionsToSql/ExpResolveAccessory.cs index b9a9c0feb..15ed1a8c6 100644 --- a/SqlSugar/Expressions/ExpResolveAccessory.cs +++ b/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 _Parameters { get; set; } + protected List _Parameters { get; set; } } } diff --git a/SqlSugar/Expressions/ExpTool.cs b/SqlSugar/ExpressionsToSql/ExpTool.cs similarity index 100% rename from SqlSugar/Expressions/ExpTool.cs rename to SqlSugar/ExpressionsToSql/ExpTool.cs diff --git a/SqlSugar/ExpressionsToSql/ExpressionContext.cs b/SqlSugar/ExpressionsToSql/ExpressionContext.cs new file mode 100644 index 000000000..8dfa744f1 --- /dev/null +++ b/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 Parameters + { + get + { + return PubMethod.IsNullReturnNew(base._Parameters); + } + set + { + base._Parameters = value; + } + } + + public int Index { get; set; } + } +} diff --git a/SqlSugar/Entities/ExpressionParameter.cs b/SqlSugar/ExpressionsToSql/ExpressionParameter.cs similarity index 64% rename from SqlSugar/Entities/ExpressionParameter.cs rename to SqlSugar/ExpressionsToSql/ExpressionParameter.cs index 2d39c5c57..adf499df6 100644 --- a/SqlSugar/Entities/ExpressionParameter.cs +++ b/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; } } } diff --git a/SqlSugar/Enum/ResolveExpressType.cs b/SqlSugar/ExpressionsToSql/ResolveExpressType.cs similarity index 100% rename from SqlSugar/Enum/ResolveExpressType.cs rename to SqlSugar/ExpressionsToSql/ResolveExpressType.cs diff --git a/SqlSugar/SqlSugar.csproj b/SqlSugar/SqlSugar.csproj index 0ecabb369..f740d7d25 100644 --- a/SqlSugar/SqlSugar.csproj +++ b/SqlSugar/SqlSugar.csproj @@ -97,7 +97,7 @@ - + @@ -106,21 +106,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/SqlSugar/bin/Debug/SqlSugar.dll b/SqlSugar/bin/Debug/SqlSugar.dll index e05646c2f..962751266 100644 Binary files a/SqlSugar/bin/Debug/SqlSugar.dll and b/SqlSugar/bin/Debug/SqlSugar.dll differ diff --git a/SqlSugar/bin/Debug/SqlSugar.pdb b/SqlSugar/bin/Debug/SqlSugar.pdb index 6aab39ccc..fa6041745 100644 Binary files a/SqlSugar/bin/Debug/SqlSugar.pdb and b/SqlSugar/bin/Debug/SqlSugar.pdb differ diff --git a/SqlSugar/obj/Debug/SqlSugar.csproj.FileListAbsolute.txt b/SqlSugar/obj/Debug/SqlSugar.csproj.FileListAbsolute.txt index 9a47395a4..c7414cb31 100644 --- a/SqlSugar/obj/Debug/SqlSugar.csproj.FileListAbsolute.txt +++ b/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 diff --git a/SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache b/SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache deleted file mode 100644 index cf78a08b2..000000000 Binary files a/SqlSugar/obj/Debug/SqlSugar.csprojResolveAssemblyReference.cache and /dev/null differ diff --git a/SqlSugar/obj/Debug/SqlSugar.dll b/SqlSugar/obj/Debug/SqlSugar.dll index e05646c2f..962751266 100644 Binary files a/SqlSugar/obj/Debug/SqlSugar.dll and b/SqlSugar/obj/Debug/SqlSugar.dll differ diff --git a/SqlSugar/obj/Debug/SqlSugar.pdb b/SqlSugar/obj/Debug/SqlSugar.pdb index 6aab39ccc..fa6041745 100644 Binary files a/SqlSugar/obj/Debug/SqlSugar.pdb and b/SqlSugar/obj/Debug/SqlSugar.pdb differ