From c7f099b7c60b69eb599f1fde2967989b4b0f8d93 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 18 Jun 2023 20:20:07 +0800 Subject: [PATCH] Synchronization code --- .../Abstract/QueryableProvider/Includes.cs | 71 +++++++++++++++++++ .../QueryableProvider/QueryMethodInfo.cs | 12 ++++ .../SqlSugar/Interface/IIncludes.cs | 1 + .../Realization/Oracle/DbBind/OracleDbBind.cs | 1 + .../SqlBuilder/OracleExpressionContext.cs | 4 ++ 5 files changed, 89 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs index 4cabc3899..daa3161fa 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -15,11 +16,81 @@ namespace SqlSugar _Includes(this.Context, include1,include2); return this; } + public ISugarQueryable IncludesByExpression3(Expression include1, Expression include2, Expression include3) + { + _Includes(this.Context, include1, include2, include3); + return this; + } public ISugarQueryable IncludesByExpression(Expression include1) { _Includes(this.Context, include1); return this; } + public ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2) + { + var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression2") + .First(); + List parametres = new List(); + List types = new List(); + var entityInfo = this.EntityInfo; + method = GetIncludesByNameStringMethod(types,navMemberName, method, parametres, entityInfo); + //var navFirst = GetNavColumnInfo(navMemberName, entityInfo); + var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types,thenNavMemberName2, method, parametres, entityInfo2); + method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast().ToArray()); + return this; + } + public ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2,string thenNavMemberName3) + { + var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression3") + .First(); + List parametres = new List(); + List types = new List(); + var entityInfo = this.EntityInfo; + method = GetIncludesByNameStringMethod(types, navMemberName, method, parametres, entityInfo); + //var navFirst = GetNavColumnInfo(navMemberName, entityInfo); + var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName2, method, parametres, entityInfo2); + var entityInfo3 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName3, method, parametres, entityInfo3); + method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast().ToArray()); + return this; + } + + private static MethodInfo GetIncludesByNameStringMethod(List types,string navMemberName, MethodInfo method, List parametres, EntityInfo entityInfo) + { + var navFirst = GetNavColumnInfo(navMemberName, entityInfo); + parametres.AddRange(GetIncludesByNameStringParameters(entityInfo.Type, navFirst)); + if (navFirst.PropertyInfo.PropertyType.FullName.IsCollectionsList()) + { + types.Add(navFirst.PropertyInfo.PropertyType.GetGenericArguments()[0]); + } + else + { + types.Add(navFirst.PropertyInfo.PropertyType); + } + return method; + } + + private static EntityColumnInfo GetNavColumnInfo(string navMemberName, EntityInfo entityInfo) + { + return entityInfo.Columns.Where(it => it.Navigat != null && it.PropertyName.EqualCase(navMemberName)).FirstOrDefault(); + } + + private static List GetIncludesByNameStringParameters(Type type,EntityColumnInfo item) + { + var parametres = new List { }; + var properyType = item.PropertyInfo.PropertyType; + var properyItemType = properyType; + if (properyType.FullName.IsCollectionsList()) + { + properyItemType = properyType.GetGenericArguments()[0]; + } + var exp = ExpressionBuilderHelper.CreateExpressionSelectField(type, item.PropertyName, properyType); + parametres.Add(exp); + return parametres; + } + public ISugarQueryable IncludesByNameString(string navMemberName) { var navs = this.EntityInfo.Columns.Where(it => it.Navigat != null&&it.PropertyName.EqualCase(navMemberName)).ToList(); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs index a59ffb9bb..409c262f2 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryMethodInfo.cs @@ -178,6 +178,18 @@ namespace SqlSugar this.QueryableObj = method.Invoke(QueryableObj, new object[] { navProperyName }); return this; } + public QueryMethodInfo Includes(string navProperyName,string thenNavProperyName2) + { + var method = QueryableObj.GetType().GetMyMethod("IncludesByNameString", 2, typeof(string),typeof(string)); + this.QueryableObj = method.Invoke(QueryableObj, new object[] { navProperyName , thenNavProperyName2 }); + return this; + } + public QueryMethodInfo Includes(string navProperyName, string thenNavProperyName2, string thenNavProperyName3) + { + var method = QueryableObj.GetType().GetMyMethod("IncludesByNameString", 3, typeof(string), typeof(string),typeof(string)); + this.QueryableObj = method.Invoke(QueryableObj, new object[] { navProperyName, thenNavProperyName2 , thenNavProperyName3 }); + return this; + } #endregion #region Result diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs index 964089b2e..38d7cfea5 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs @@ -17,6 +17,7 @@ namespace SqlSugar ISugarQueryable IncludesByExpression2(Expression include1, Expression include2); ISugarQueryable IncludesByExpression(Expression include1); ISugarQueryable IncludesByNameString(string navMemberName); + ISugarQueryable IncludesByNameString(string navMemberName,string thenNavMemberName2); ISugarQueryable IncludesAllFirstLayer(params string[] ignoreProperyNameList); ISugarQueryable IncludesAllSecondLayer(Expression> expression,params string[] ignoreProperyNameList); ISugarQueryable Includes(Expression>> include1); diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs index 076d15cb6..dffc54397 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs @@ -113,6 +113,7 @@ namespace SqlSugar new KeyValuePair("rowid",CSharpDataType.@string), new KeyValuePair("date",CSharpDataType.DateTime), + new KeyValuePair("timestamptz",CSharpDataType.DateTime), new KeyValuePair("timestamp",CSharpDataType.DateTime), new KeyValuePair("timestamp with local time zone",CSharpDataType.DateTime), new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs index 4b468ebc7..33a85d0e5 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs @@ -33,6 +33,10 @@ namespace SqlSugar } public override string GetTranslationColumnName(string columnName) { + if (columnName == "systimestamp") + { + return columnName; + } if (columnName.Contains(":")) return base.GetTranslationColumnName(columnName); else if (columnName.Contains("\".\""))