From e93f056230c476000dbcc8fc6ef26aeb8a0bec18 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 6 Aug 2022 00:08:26 +0800 Subject: [PATCH] Update .net core project --- .../Abstract/DbMaintenanceProvider/Methods.cs | 11 +++++++++-- .../Abstract/QueryableProvider/NavigatManager.cs | 1 + .../Entities/Mapping/SugarMappingAttribute.cs | 11 +++++++++++ .../ExpressionsToSql/DbMethods/DefaultDbMethod.cs | 4 ++-- .../SqlSugar/ExpressionsToSql/ExpressionContext.cs | 6 +++++- .../ResolveItems/OneToOneNavgateExpression.cs | 1 + .../ResolveItems/OneToOneNavgateExpressionN.cs | 4 ++++ Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs | 4 ++++ 8 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index f67d3c89b..29aa126ee 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -221,13 +221,20 @@ namespace SqlSugar var dtColumInfo = dtColums.First(it => it.ColumnName.EqualCase(columnInfo.DbColumnName)); var type = UtilMethods.GetUnderType(dtColumInfo.DataType); var value= type==UtilConstants.StringType?(object)"": Activator.CreateInstance(type); + if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle) + { + value = columnInfo.DefaultValue; + if (value.Equals("")) + { + value = "empty"; + } + } var dt = new Dictionary(); dt.Add(columnInfo.DbColumnName, value); this.Context.Updateable(dt) .AS(tableName) .Where($"{columnInfo.DbColumnName} is null ").ExecuteCommand(); - if(this.Context.CurrentConnectionConfig.DbType!=DbType.Oracle) - columnInfo.IsNullable = false; + columnInfo.IsNullable = false; UpdateColumn(tableName, columnInfo); } return true; diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs index 005518e92..c0ffa3263 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavigatManager.cs @@ -327,6 +327,7 @@ namespace SqlSugar { var sqlObj = GetWhereSql(navObjectNameColumnInfo.Navigat.Name); var navList = selector(this.Context.Queryable().AS(navEntityInfo.DbTableName) + .WhereIF(navObjectNameColumnInfo.Navigat.WhereSql.HasValue(), navObjectNameColumnInfo.Navigat.WhereSql) .WhereIF(sqlObj.WhereString.HasValue(),sqlObj.WhereString) .AddParameters(sqlObj.Parameters).Where(conditionalModels)); var groupQuery = (from l in list diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs index 85d85b1b1..c1c2de3de 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/Mapping/SugarMappingAttribute.cs @@ -228,6 +228,7 @@ namespace SqlSugar public string MappingAId { get; set; } public string MappingBId { get; set; } public NavigateType NavigatType { get; set; } + public string WhereSql { get; set; } public Navigate(NavigateType navigatType,string name) { this.Name = name; @@ -239,6 +240,16 @@ namespace SqlSugar this.Name2 = lastName; this.NavigatType = navigatType; } + + public Navigate(NavigateType navigatType, string firstName, string lastName,string whereSql) + { + this.Name = firstName; + this.Name2 = lastName; + this.NavigatType = navigatType; + this.WhereSql = whereSql; + Check.ExceptionEasy(navigatType != NavigateType.OneToOne, "Currently, only one-to-one navigation configuration Sql conditions are supported", "目前导航配置Sql条件只支持一对一"); + } + public Navigate(Type MappingTableType,string typeAiD,string typeBId) { this.MappingType = MappingTableType; diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs index ff70269ce..4bd410aa9 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs @@ -12,11 +12,11 @@ namespace SqlSugar { if (model.Args.Count == 1) { - return $"row_number() over(order by {model.Args[0].MemberName})"; + return $"row_number() over(order by {model.Args[0].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})"; } else { - return $"row_number() over( partition by {model.Args[1].MemberName} order by {model.Args[0].MemberName})"; + return $"row_number() over( partition by {model.Args[1].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')} order by {model.Args[0].MemberName.ObjToString().TrimEnd('\'').TrimStart('\'')})"; } } public virtual string RowCount(MethodCallExpressionModel model) diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs index 44955fe55..b9d72b446 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ExpressionContext.cs @@ -178,7 +178,11 @@ namespace SqlSugar { var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase)); var name = (mappingInfo == null ? entityName : mappingInfo.DbTableName); - if (name.Contains(".")) + if (name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight)) + { + return name; + } + else if (name.Contains(".")) { return string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight)); } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs index d4e3a6c41..115c40e8f 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpression.cs @@ -98,6 +98,7 @@ namespace SqlSugar selectName = queryable.QueryBuilder.Builder.GetTranslationColumnName(selectName); mapper.Sql = queryable .AS(this.ProPertyEntity.DbTableName) + .WhereIF(Navigat.WhereSql.HasValue(),Navigat.WhereSql) .Where($" {ShorName}.{name}={pk} ").Select(selectName).ToSql().Key; mapper.Sql = $" ({mapper.Sql}) "; return mapper; diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs index 2722fa00b..abf37799c 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToOneNavgateExpressionN.cs @@ -66,6 +66,10 @@ namespace SqlSugar var navColum = item.ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == item.Nav.Name); Check.ExceptionEasy(pkColumn == null, $"{item.ThisEntityInfo.EntityName} need PrimayKey", $"使用导航属性{item.ThisEntityInfo.EntityName} 缺少主键"); var on = $" {ToShortName(shortName)}.{queryable.SqlBuilder.GetTranslationColumnName(pkColumn.DbColumnName)}={ToShortName(formInfo.ThisEntityInfo.DbTableName + (i - 1))}.{queryable.SqlBuilder.GetTranslationColumnName(navColum.DbColumnName)}"; + if (item.Nav.WhereSql.HasValue()) + { + on = (on + " AND " + item.Nav.WhereSql); + } queryable.AddJoinInfo(item.ThisEntityInfo.DbTableName,ToShortName(shortName), on, JoinType.Inner); ++i; lastShortName = shortName; diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index 2ac280d1c..646b3a9d2 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -589,6 +589,10 @@ namespace SqlSugar { return Convert.ToInt32(item.FieldValue); } + else if (item.FieldValue!=null&&item.CSharpTypeName.EqualCase(UtilConstants.BoolType.Name)) + { + return Convert.ToBoolean(item.FieldValue.ToLower()); + } else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name)) { return Convert.ToInt64(item.FieldValue);