From c52d05f2d96a2ce97407705f02a0cc6bd4b5c3a6 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sat, 19 Jun 2021 12:44:07 +0800 Subject: [PATCH] Update core --- .../SqlBuilderProvider/SqlBuilderProvider.cs | 4 ++++ .../ExpressionsToSql/Subquery/Items/SubAnd.cs | 3 ++- .../Subquery/Items/SubInnerJoin.cs | 2 +- .../Subquery/Items/SubLeftJoin.cs | 2 +- .../ExpressionsToSql/Subquery/Items/SubMax.cs | 9 +++++++++ .../ExpressionsToSql/Subquery/Items/SubMin.cs | 9 +++++++++ .../ExpressionsToSql/Subquery/Items/SubSelect.cs | 5 ++++- .../ExpressionsToSql/Subquery/Items/SubSum.cs | 9 +++++++++ .../ExpressionsToSql/Subquery/SubResolve.cs | 6 ++++++ .../ExpressionsToSql/Subquery/Subquerable.cs | 16 ++++++++++++++++ .../SqlBuilder/PostgreSQLUpdateBuilder.cs | 4 +++- .../DbMaintenance/SqlServerDbMaintenance.cs | 11 +++++++++-- .../SqlSeverTest/SqlSugar/SqlSugarClient.cs | 4 ++++ 13 files changed, 77 insertions(+), 7 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs index 36b82e54b..a98e6ae43 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs @@ -35,6 +35,10 @@ namespace SqlSugar { return name; } + if (Context.MappingTables == null) + { + return name; + } var context = this.Context; var mappingInfo = context .MappingTables diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs index 74bfbc1d0..b96d64706 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubAnd.cs @@ -60,7 +60,8 @@ namespace SqlSugar } var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; - result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); + if (this.Context.JoinIndex == 0) + result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); return result; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs index 02b7d26a1..d78cc4d04 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs @@ -50,7 +50,7 @@ namespace SqlSugar var joinString =string.Format(" {2} INNER JOIN {1} {0} ", this.Context.GetTranslationColumnName(parameter.Name), tableName, - this.Context.JoinIndex==0?name:""); + this.Context.JoinIndex==1?name:""); var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple); //var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; this.Context.JoinIndex++; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs index 5bc58bf4f..f46e25194 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs @@ -50,7 +50,7 @@ namespace SqlSugar var joinString =string.Format(" {2} LEFT JOIN {1} {0} ", this.Context.GetTranslationColumnName(parameter.Name), tableName, - this.Context.JoinIndex==0?name:""); + this.Context.JoinIndex==1?name:""); var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple); //var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; this.Context.JoinIndex++; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs index aee39de80..e2e46b010 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs @@ -49,6 +49,15 @@ namespace SqlSugar { argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand; } + var argLambda = argExp as LambdaExpression; + if (this.Context.InitMappingInfo != null && argLambda != null && argLambda.Parameters.Count > 0) + { + foreach (var item in argLambda.Parameters) + { + this.Context.InitMappingInfo(item.Type); + } + this.Context.RefreshMapping(); + } var result = "MAX(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot; result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs index 41fd5617f..aeef64ec3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs @@ -49,6 +49,15 @@ namespace SqlSugar { argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand; } + var argLambda = argExp as LambdaExpression; + if (this.Context.InitMappingInfo != null && argLambda != null && argLambda.Parameters.Count > 0) + { + foreach (var item in argLambda.Parameters) + { + this.Context.InitMappingInfo(item.Type); + } + this.Context.RefreshMapping(); + } var result = "MIN(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot; result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs index d2b853feb..11869c486 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs @@ -49,7 +49,10 @@ namespace SqlSugar this.Context.InitMappingInfo(entityType); this.Context.RefreshMapping(); } - return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle); + if(this.Context.JoinIndex==0) + return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle); + else + return SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldMultiple); } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs index 03f1454b4..c6b771583 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs @@ -49,6 +49,15 @@ namespace SqlSugar { argExp =((argExp as LambdaExpression).Body as UnaryExpression).Operand; } + var argLambda = argExp as LambdaExpression; + if (this.Context.InitMappingInfo != null&& argLambda != null&&argLambda.Parameters.Count>0) + { + foreach (var item in argLambda.Parameters) + { + this.Context.InitMappingInfo(item.Type); + } + this.Context.RefreshMapping(); + } var result = "SUM(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple)+")"; var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot; result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs index dac6cbb0e..3807b861c 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs @@ -135,11 +135,17 @@ namespace SqlSugar } isubList = isubList.OrderBy(it => it.Sort).ToList(); var isHasWhere = isubList.Where(it => it is SubWhere).Any(); + var isJoin = isubList.Any(it => it is SubInnerJoin || it is SubLeftJoin); + if (isJoin) + { + this.context.JoinIndex++; + } List result = isubList.Select(it => { it.HasWhere = isHasWhere; return it.GetValue(it.Expression); }).ToList(); + this.context.JoinIndex = 0; return result; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs index ba7a1b9b6..67ce6cd53 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Subquery/Subquerable.cs @@ -27,6 +27,22 @@ namespace SqlSugar { return this; } + public Subqueryable Where(Func expression) + { + return this; + } + public Subqueryable Where(Func expression) + { + return this; + } + public Subqueryable Where(Func expression) + { + return this; + } + public Subqueryable Where(Func expression) + { + return this; + } public Subqueryable WhereIF(bool isWhere,Func expression) { return this; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs index 61c26f238..74b6f6022 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs @@ -136,7 +136,9 @@ namespace SqlSugar typeName = "long"; if (typeName == "int16") typeName = "short"; - + if (typeName == "boolean") + typeName = "bool"; + var isAnyType = PostgreSQLDbBind.MappingTypesConst.Where(x => x.Value.ToString().ToLower() == typeName).Any(); if (isAnyType) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs index 9b56752c8..01153eb45 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs @@ -323,9 +323,16 @@ namespace SqlSugar { if (databaseDirectory != null) { - if (!FileHelper.IsExistDirectory(databaseDirectory)) + try { - FileHelper.CreateDirectory(databaseDirectory); + if (!FileHelper.IsExistDirectory(databaseDirectory)) + { + FileHelper.CreateDirectory(databaseDirectory); + } + } + catch + { + //Databases and sites are not in the same service } } var oldDatabaseName = this.Context.Ado.Connection.Database; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index e5aec9502..453fe63bc 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -589,6 +589,10 @@ namespace SqlSugar db.Context = new SqlSugarProvider(db.ConnectionConfig); } var intiAop=db.Context.Aop; + if (db.Context.CurrentConnectionConfig.AopEvents == null) + { + db.Context.CurrentConnectionConfig.AopEvents = new AopEvents(); + } return db.Context; } public void ChangeDatabase(dynamic configId)