From 9f26b1947ffc2a6ec822723cc51e186f72d9867a Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Mon, 24 Oct 2022 22:17:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=B1=E5=AD=90=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=BD=BF=E7=94=A8=E6=97=B6GetProperty=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84bug,=E5=8F=91=E5=B8=836.8.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShardingCoreBenchmark/EFCoreCrud.cs | 1 - .../ShardingCoreBenchmark5x/EFCoreCrud.cs | 1 - .../Sample.AutoCreateIfPresent/AreaDevice.cs | 5 +- samples/Sample.AutoCreateIfPresent/Program.cs | 1 - samples/Sample.BulkConsole/Program.cs | 1 - samples/Sample.MySql/Startup.cs | 1 - .../Sample.NoShardingMultiLevel/Program.cs | 2 +- samples/Sample.SqlServer/Startup.cs | 1 - ...lMergeSqlServerQuerySqlGeneratorFactory.cs | 4 +- samples/Sample.SqlServer3x/Startup.cs | 1 - .../StartupExtension.cs | 1 - .../StartupExtension.cs | 1 - .../StartupExtension.cs | 1 - .../AbstractShardingAbpZeroDbContext.cs | 2 +- .../DIExtension.cs | 1 - .../EntityMetadataDataSourceBuilder.cs | 5 +- .../EntityMetadataTableBuilder.cs | 5 +- .../Extensions/ExpressionExtension.cs | 8 +-- .../Extensions/ObjectExtension.cs | 55 +++++++++++++++++-- .../ShardingPageExtension.cs | 2 +- .../Extensions/StringFieldOrderExtension.cs | 6 +- .../AggregateExtensions/AggregateExtension.cs | 20 +++---- .../Visitors/QuerySelectDiscoverVisitor.cs | 6 +- .../Visitors/QueryableExtraDiscoverVisitor.cs | 10 ++-- src/ShardingCore/ShardingCoreExtension.cs | 10 ---- test/ShardingCore.Test/Startup.cs | 1 - test/ShardingCore.Test2x/Startup.cs | 1 - test/ShardingCore.Test3x/Startup.cs | 1 - test/ShardingCore.Test5x/Startup.cs | 1 - 29 files changed, 91 insertions(+), 64 deletions(-) diff --git a/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs b/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs index 0d204a65..4ec55f0c 100644 --- a/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs +++ b/benchmarks/ShardingCoreBenchmark/EFCoreCrud.cs @@ -50,7 +50,6 @@ namespace ShardingCore6x }).AddShardingCore(); var buildServiceProvider = services.BuildServiceProvider(); - buildServiceProvider.UseAutoShardingCreate(); buildServiceProvider.UseAutoTryCompensateTable(); ICollection orders = new LinkedList(); diff --git a/benchmarks/ShardingCoreBenchmark5x/EFCoreCrud.cs b/benchmarks/ShardingCoreBenchmark5x/EFCoreCrud.cs index bd359b00..74aedd96 100644 --- a/benchmarks/ShardingCoreBenchmark5x/EFCoreCrud.cs +++ b/benchmarks/ShardingCoreBenchmark5x/EFCoreCrud.cs @@ -48,7 +48,6 @@ namespace ShardingCoreBenchmark5x }).ReplaceService().EnsureConfig(); var buildServiceProvider = services.BuildServiceProvider(); - buildServiceProvider.UseAutoShardingCreate(); buildServiceProvider.UseAutoTryCompensateTable(); ICollection orders = new LinkedList(); diff --git a/samples/Sample.AutoCreateIfPresent/AreaDevice.cs b/samples/Sample.AutoCreateIfPresent/AreaDevice.cs index 25e08c27..ce02a04b 100644 --- a/samples/Sample.AutoCreateIfPresent/AreaDevice.cs +++ b/samples/Sample.AutoCreateIfPresent/AreaDevice.cs @@ -1,5 +1,8 @@ -namespace Sample.AutoCreateIfPresent +using System.ComponentModel.DataAnnotations.Schema; + +namespace Sample.AutoCreateIfPresent { + [Table("aaa")] public class AreaDevice { public string Id { get; set; } diff --git a/samples/Sample.AutoCreateIfPresent/Program.cs b/samples/Sample.AutoCreateIfPresent/Program.cs index aef2b64e..3a472cde 100644 --- a/samples/Sample.AutoCreateIfPresent/Program.cs +++ b/samples/Sample.AutoCreateIfPresent/Program.cs @@ -50,7 +50,6 @@ if (app.Environment.IsDevelopment()) // app.UseSwagger(); // app.UseSwaggerUI(); } -app.Services.UseAutoShardingCreate(); app.Services.UseAutoTryCompensateTable(); diff --git a/samples/Sample.BulkConsole/Program.cs b/samples/Sample.BulkConsole/Program.cs index b01e0da4..861e4b68 100644 --- a/samples/Sample.BulkConsole/Program.cs +++ b/samples/Sample.BulkConsole/Program.cs @@ -47,7 +47,6 @@ namespace Sample.BulkConsole }).ReplaceService().EnsureConfig(); var serviceProvider = services.BuildServiceProvider(); - serviceProvider.UseAutoShardingCreate(); serviceProvider.UseAutoTryCompensateTable(); using (var serviceScope = serviceProvider.CreateScope()) { diff --git a/samples/Sample.MySql/Startup.cs b/samples/Sample.MySql/Startup.cs index ea292331..111b67a3 100644 --- a/samples/Sample.MySql/Startup.cs +++ b/samples/Sample.MySql/Startup.cs @@ -181,7 +181,6 @@ namespace Sample.MySql } // app.ApplicationServices.UseAutoTryCompensateTable(); - // app.ApplicationServices.UseAutoShardingCreate(); // var shardingRuntimeContext = app.ApplicationServices.GetRequiredService(); // var entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager(); // var entityMetadata = entityMetadataManager.TryGet(); diff --git a/samples/Sample.NoShardingMultiLevel/Program.cs b/samples/Sample.NoShardingMultiLevel/Program.cs index 7b4f6fd3..88eeca59 100644 --- a/samples/Sample.NoShardingMultiLevel/Program.cs +++ b/samples/Sample.NoShardingMultiLevel/Program.cs @@ -50,7 +50,7 @@ builder.Services.AddShardingDbContext() var app = builder.Build(); // Configure the HTTP request pipeline. -app.Services.UseAutoShardingCreate(); +// app.Services.UseAutoShardingCreate(); app.Services.UseAutoTryCompensateTable(); app.UseAuthorization(); diff --git a/samples/Sample.SqlServer/Startup.cs b/samples/Sample.SqlServer/Startup.cs index fa729412..049c6480 100644 --- a/samples/Sample.SqlServer/Startup.cs +++ b/samples/Sample.SqlServer/Startup.cs @@ -125,7 +125,6 @@ namespace Sample.SqlServer var migrator = defaultShardingDbContext.GetService(); migrator.Migrate("InitialCreate"); } - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); app.UseRouting(); diff --git a/samples/Sample.SqlServer/UnionAllMerge/UnionAllMergeSqlServerQuerySqlGeneratorFactory.cs b/samples/Sample.SqlServer/UnionAllMerge/UnionAllMergeSqlServerQuerySqlGeneratorFactory.cs index 8dfecc5f..b13e82a6 100644 --- a/samples/Sample.SqlServer/UnionAllMerge/UnionAllMergeSqlServerQuerySqlGeneratorFactory.cs +++ b/samples/Sample.SqlServer/UnionAllMerge/UnionAllMergeSqlServerQuerySqlGeneratorFactory.cs @@ -69,7 +69,7 @@ namespace Sample.SqlServer.UnionAllMerge { var tails = tableRouteResults.Select(o => o.ReplaceTables.FirstOrDefault(r => r.EntityType==entityMetadatas[0].EntityType)?.Tail).ToHashSet(); - var sqlGenerationHelper = typeof(QuerySqlGenerator).GetTypeFieldValue(this, "_sqlGenerationHelper") as ISqlGenerationHelper; + var sqlGenerationHelper = ObjectExtension.GetTypeFieldValue(typeof(QuerySqlGenerator),this, "_sqlGenerationHelper") as ISqlGenerationHelper; string newTableName = null; if (tails.Count == 1) { @@ -80,7 +80,7 @@ namespace Sample.SqlServer.UnionAllMerge newTableName = "(" + string.Join(" union all ", tails.Select(tail => $"select * from {sqlGenerationHelper.DelimitIdentifier($"{tableExpression.Name}{entityMetadatas[0].TableSeparator}{tail}", tableExpression.Schema)}")) + ")"; } - var relationalCommandBuilder = typeof(QuerySqlGenerator).GetTypeFieldValue(this, "_relationalCommandBuilder") as IRelationalCommandBuilder; + var relationalCommandBuilder = ObjectExtension.GetTypeFieldValue(typeof(QuerySqlGenerator),this, "_relationalCommandBuilder") as IRelationalCommandBuilder; relationalCommandBuilder.Append(newTableName).Append(this.AliasSeparator).Append(sqlGenerationHelper.DelimitIdentifier(tableExpression.Alias)); return tableExpression; } diff --git a/samples/Sample.SqlServer3x/Startup.cs b/samples/Sample.SqlServer3x/Startup.cs index fc62d00d..48f29d21 100644 --- a/samples/Sample.SqlServer3x/Startup.cs +++ b/samples/Sample.SqlServer3x/Startup.cs @@ -90,7 +90,6 @@ namespace Sample.SqlServer3x app.UseDeveloperExceptionPage(); } - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); app.UseRouting(); diff --git a/samples/Sample.SqlServerShardingAll/StartupExtension.cs b/samples/Sample.SqlServerShardingAll/StartupExtension.cs index 66e59061..58222d9e 100644 --- a/samples/Sample.SqlServerShardingAll/StartupExtension.cs +++ b/samples/Sample.SqlServerShardingAll/StartupExtension.cs @@ -13,7 +13,6 @@ namespace Sample.SqlServerShardingAll { public static void UseShardingCore(this IApplicationBuilder app) { - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); } public static void InitSeed(this IApplicationBuilder app) diff --git a/samples/Sample.SqlServerShardingDataSource/StartupExtension.cs b/samples/Sample.SqlServerShardingDataSource/StartupExtension.cs index 52feab9c..40f41d3c 100644 --- a/samples/Sample.SqlServerShardingDataSource/StartupExtension.cs +++ b/samples/Sample.SqlServerShardingDataSource/StartupExtension.cs @@ -13,7 +13,6 @@ namespace Sample.SqlServerShardingDataSource { public static void UseShardingCore(this IApplicationBuilder app) { - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); } public static void InitSeed(this IApplicationBuilder app) diff --git a/samples/Sample.SqlServerShardingTable/StartupExtension.cs b/samples/Sample.SqlServerShardingTable/StartupExtension.cs index 6925138c..022b5afa 100644 --- a/samples/Sample.SqlServerShardingTable/StartupExtension.cs +++ b/samples/Sample.SqlServerShardingTable/StartupExtension.cs @@ -14,7 +14,6 @@ namespace Sample.SqlServerShardingTable { public static void UseShardingCore(this IApplicationBuilder app) { - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); } public static void InitSeed(this IApplicationBuilder app) diff --git a/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs b/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs index 673bbfe3..b2cb0748 100644 --- a/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs +++ b/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs @@ -28,7 +28,7 @@ namespace Samples.AbpSharding { public abstract class AbstractShardingAbpZeroDbContext : AbpZeroDbContext, - IShardingDbContext + IShardingDbContext,IShardingTableDbContext where TTenant : AbpTenant where TRole : AbpRole where TUser : AbpUser diff --git a/samples/Samples.AutoByDate.SqlServer/DIExtension.cs b/samples/Samples.AutoByDate.SqlServer/DIExtension.cs index 6852b6a2..dd8ed0e6 100644 --- a/samples/Samples.AutoByDate.SqlServer/DIExtension.cs +++ b/samples/Samples.AutoByDate.SqlServer/DIExtension.cs @@ -15,7 +15,6 @@ namespace Samples.AutoByDate.SqlServer { public static IApplicationBuilder UseShardingCore(this IApplicationBuilder app) { - app.ApplicationServices.UseAutoShardingCreate(); app.ApplicationServices.UseAutoTryCompensateTable(); return app; } diff --git a/src/ShardingCore/Core/EntityMetadatas/EntityMetadataDataSourceBuilder.cs b/src/ShardingCore/Core/EntityMetadatas/EntityMetadataDataSourceBuilder.cs index 262b41c6..118d79c4 100644 --- a/src/ShardingCore/Core/EntityMetadatas/EntityMetadataDataSourceBuilder.cs +++ b/src/ShardingCore/Core/EntityMetadatas/EntityMetadataDataSourceBuilder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Text; using Microsoft.EntityFrameworkCore.Infrastructure; +using ShardingCore.Extensions; #if NETCOREAPP2_0 using Microsoft.EntityFrameworkCore.Internal; @@ -37,7 +38,7 @@ namespace ShardingCore.Core.EntityMetadatas /// public EntityMetadataDataSourceBuilder ShardingProperty(string propertyName) { - var propertyInfo = typeof(TEntity).GetProperty(propertyName); + var propertyInfo = typeof(TEntity).GetUltimateShadowingProperty(propertyName); _entityMetadata.SetShardingDataSourceProperty(propertyInfo); return this; } @@ -49,7 +50,7 @@ namespace ShardingCore.Core.EntityMetadatas } public EntityMetadataDataSourceBuilder ShardingExtraProperty(string propertyName) { - var propertyInfo = typeof(TEntity).GetProperty(propertyName); + var propertyInfo = typeof(TEntity).GetUltimateShadowingProperty(propertyName); _entityMetadata.AddExtraSharingDataSourceProperty(propertyInfo); return this; } diff --git a/src/ShardingCore/Core/EntityMetadatas/EntityMetadataTableBuilder.cs b/src/ShardingCore/Core/EntityMetadatas/EntityMetadataTableBuilder.cs index 4806837b..8eb3da3e 100644 --- a/src/ShardingCore/Core/EntityMetadatas/EntityMetadataTableBuilder.cs +++ b/src/ShardingCore/Core/EntityMetadatas/EntityMetadataTableBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Infrastructure; +using ShardingCore.Extensions; #if NETCOREAPP2_0 using Microsoft.EntityFrameworkCore.Internal; @@ -34,7 +35,7 @@ namespace ShardingCore.Core.EntityMetadatas } public EntityMetadataTableBuilder ShardingProperty(string propertyName) { - var propertyInfo = typeof(TEntity).GetProperty(propertyName); + var propertyInfo = typeof(TEntity).GetUltimateShadowingProperty(propertyName); _entityMetadata.SetShardingTableProperty(propertyInfo); return this; } @@ -46,7 +47,7 @@ namespace ShardingCore.Core.EntityMetadatas } public EntityMetadataTableBuilder ShardingExtraProperty(string propertyName) { - var propertyInfo = typeof(TEntity).GetProperty(propertyName); + var propertyInfo = typeof(TEntity).GetUltimateShadowingProperty(propertyName); _entityMetadata.AddExtraSharingTableProperty(propertyInfo); return this; } diff --git a/src/ShardingCore/Extensions/ExpressionExtension.cs b/src/ShardingCore/Extensions/ExpressionExtension.cs index 4ff9e66c..185ef889 100644 --- a/src/ShardingCore/Extensions/ExpressionExtension.cs +++ b/src/ShardingCore/Extensions/ExpressionExtension.cs @@ -19,7 +19,7 @@ namespace ShardingCore.Extensions public static void SetPropertyValue(this T t, string name, object value) { Type type = t.GetType(); - PropertyInfo p = type.GetProperty(name); + PropertyInfo p = type.GetUltimateShadowingProperty(name); if (p == null) { throw new Exception($"type:{typeof(T)} not found [{name}] properity "); @@ -56,7 +56,7 @@ namespace ShardingCore.Extensions if (propertyExpression.Contains(".")) { String[] childProperties = propertyExpression.Split('.'); - property = entityType.GetProperty(childProperties[0]); + property = entityType.GetUltimateShadowingProperty(childProperties[0]); //propertyAccess = Expression.MakeMemberAccess(parameter, property); for (int i = 1; i < childProperties.Length; i++) { @@ -64,13 +64,13 @@ namespace ShardingCore.Extensions { throw new ShardingCoreException($"property:[{propertyExpression}] not in type:[{entityType}]"); } - property = property.PropertyType.GetProperty(childProperties[i]); + property = property.PropertyType.GetUltimateShadowingProperty(childProperties[i]); //propertyAccess = Expression.MakeMemberAccess(propertyAccess, property); } } else { - property = entityType.GetProperty(propertyExpression); + property = entityType.GetUltimateShadowingProperty(propertyExpression); //propertyAccess = Expression.MakeMemberAccess(parameter, property); } diff --git a/src/ShardingCore/Extensions/ObjectExtension.cs b/src/ShardingCore/Extensions/ObjectExtension.cs index 81498d3a..1efb6f71 100644 --- a/src/ShardingCore/Extensions/ObjectExtension.cs +++ b/src/ShardingCore/Extensions/ObjectExtension.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using ShardingCore.Core; namespace ShardingCore.Extensions { @@ -43,7 +44,7 @@ namespace ShardingCore.Extensions /// public static object GetPropertyValue(this object obj, string propertyName) { - var property = obj.GetType().GetProperty(propertyName, _bindingFlags); + var property = obj.GetType().GetUltimateShadowingProperty(propertyName, _bindingFlags); if (property != null) { return property.GetValue(obj); @@ -62,7 +63,7 @@ namespace ShardingCore.Extensions /// public static object GetTypePropertyValue(this Type type,object obj, string propertyName) { - var property=type.GetProperty(propertyName, _bindingFlags); + var property=type.GetUltimateShadowingProperty(propertyName, _bindingFlags); if (property != null) { return property.GetValue(obj); @@ -74,7 +75,7 @@ namespace ShardingCore.Extensions } public static PropertyInfo GetObjectProperty(this object obj, string propertyName) { - return obj.GetType().GetProperty(propertyName, _bindingFlags); + return obj.GetType().GetUltimateShadowingProperty(propertyName,_bindingFlags); } /// /// 类型X是否包含某个属性 @@ -84,7 +85,7 @@ namespace ShardingCore.Extensions /// public static bool ContainPropertyName(this Type type, string propertyName) { - var property = type.GetProperty(propertyName, _bindingFlags); + var property = type.GetUltimateShadowingProperty(propertyName, _bindingFlags); return property != null; } @@ -98,6 +99,52 @@ namespace ShardingCore.Extensions { return genericType.MakeGenericType(arg0Type, arg1Type); } + public static PropertyInfo GetUltimateShadowingProperty(this Type type, string name) + { + + return type.GetUltimateShadowingProperty(name,_bindingFlags); + } + /// + /// https://github.com/nunit/nunit/blob/111fc6b5550f33b4fceb6ac8693c5692e99a5747/src/NUnitFramework/framework/Internal/Reflect.cs + /// + /// + /// + /// + /// + public static PropertyInfo GetUltimateShadowingProperty(this Type type, string name, BindingFlags bindingFlags) + { + Check.NotNull(type, nameof(type)); + Check.NotNull(name, nameof(name)); + if ((bindingFlags & BindingFlags.DeclaredOnly) != 0) + { + // If you're asking us to search a hierarchy but only want properties declared in the given type, + // you're in the wrong place but okay: + return type.GetProperty(name, bindingFlags); + } + + if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == (BindingFlags.Public | BindingFlags.NonPublic)) + { + // If we're searching for both public and nonpublic properties, search for only public first + // because chances are if there is a public property, it would be very surprising to detect the private shadowing property. + + for (var publicSearchType = type; publicSearchType != null; publicSearchType = publicSearchType.GetTypeInfo().BaseType) + { + var property = publicSearchType.GetProperty(name, (bindingFlags | BindingFlags.DeclaredOnly) & ~BindingFlags.NonPublic); + if (property != null) return property; + } + + // There is no public property, so may as well not ask to include them during the second search. + bindingFlags &= ~BindingFlags.Public; + } + + for (var searchType = type; searchType != null; searchType = searchType.GetTypeInfo().BaseType) + { + var property = searchType.GetProperty(name, bindingFlags | BindingFlags.DeclaredOnly); + if (property != null) return property; + } + + return null; + } } } \ No newline at end of file diff --git a/src/ShardingCore/Extensions/ShardingPageExtensions/ShardingPageExtension.cs b/src/ShardingCore/Extensions/ShardingPageExtensions/ShardingPageExtension.cs index 3c479876..897e7cc1 100644 --- a/src/ShardingCore/Extensions/ShardingPageExtensions/ShardingPageExtension.cs +++ b/src/ShardingCore/Extensions/ShardingPageExtensions/ShardingPageExtension.cs @@ -23,7 +23,7 @@ namespace ShardingCore.Extensions.ShardingPageExtensions var entityQueryProvider = source.Provider as EntityQueryProvider??throw new ShardingCoreInvalidOperationException($"cant use sharding page that {nameof(IQueryable)} provider not {nameof(EntityQueryProvider)}"); - var shardingQueryCompiler = entityQueryProvider.GetFieldValue("_queryCompiler") as ShardingQueryCompiler??throw new ShardingCoreInvalidOperationException($"cant use sharding page that {nameof(EntityQueryProvider)} not contains {nameof(ShardingQueryCompiler)} filed named _queryCompiler"); + var shardingQueryCompiler = ObjectExtension.GetFieldValue(entityQueryProvider,"_queryCompiler") as ShardingQueryCompiler??throw new ShardingCoreInvalidOperationException($"cant use sharding page that {nameof(EntityQueryProvider)} not contains {nameof(ShardingQueryCompiler)} filed named _queryCompiler"); var dbContextAvailable = shardingQueryCompiler as IShardingDbContextAvailable; if (dbContextAvailable == null) { diff --git a/src/ShardingCore/Extensions/StringFieldOrderExtension.cs b/src/ShardingCore/Extensions/StringFieldOrderExtension.cs index f0987a03..cd7ee18c 100644 --- a/src/ShardingCore/Extensions/StringFieldOrderExtension.cs +++ b/src/ShardingCore/Extensions/StringFieldOrderExtension.cs @@ -31,17 +31,17 @@ namespace ShardingCore.Extensions if (propertyName.Contains('.')) { String[] childProperties = propertyName.Split('.'); - property = entityType.GetProperty(childProperties[0]); + property = entityType.GetUltimateShadowingProperty(childProperties[0]); propertyAccess = Expression.MakeMemberAccess(parameter, property); for (int i = 1; i < childProperties.Length; i++) { - property = property.PropertyType.GetProperty(childProperties[i]); + property = property.PropertyType.GetUltimateShadowingProperty(childProperties[i]); propertyAccess = Expression.MakeMemberAccess(propertyAccess, property); } } else { - property = entityType.GetProperty(propertyName); + property = entityType.GetUltimateShadowingProperty(propertyName); propertyAccess = Expression.MakeMemberAccess(parameter, property); } diff --git a/src/ShardingCore/Sharding/Enumerators/AggregateExtensions/AggregateExtension.cs b/src/ShardingCore/Sharding/Enumerators/AggregateExtensions/AggregateExtension.cs index 83c461b4..60ce8def 100644 --- a/src/ShardingCore/Sharding/Enumerators/AggregateExtensions/AggregateExtension.cs +++ b/src/ShardingCore/Sharding/Enumerators/AggregateExtensions/AggregateExtension.cs @@ -70,7 +70,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions .Select(o => { // property "Field1" - var mi = typeof(TSource).GetProperty(o); + var mi = typeof(TSource).GetUltimateShadowingProperty(o); // original value "o.Field1" var xOriginal = Expression.Property(xParameter, mi); @@ -117,7 +117,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions { if (source == null) throw new ArgumentNullException(nameof(source)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - PropertyInfo property = source.ElementType.GetProperty(propertyName); + PropertyInfo property = source.ElementType.GetUltimateShadowingProperty(propertyName); return source.Count(property); } @@ -203,7 +203,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions if (source == null) throw new ArgumentNullException(nameof(source)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - PropertyInfo property = source.ElementType.GetProperty(propertyName); + PropertyInfo property = source.ElementType.GetUltimateShadowingProperty(propertyName); return source.SumByProperty(property); } /// @@ -219,7 +219,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions if (source == null) throw new ArgumentNullException(nameof(source)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - PropertyInfo property = source.ElementType.GetProperty(propertyName); + PropertyInfo property = source.ElementType.GetUltimateShadowingProperty(propertyName); return source.SumByProperty(property); } //public static object Average(this IQueryable source, string member) @@ -276,7 +276,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions { if (source == null) throw new ArgumentNullException(nameof(source)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - PropertyInfo property = source.ElementType.GetProperty(propertyName); + PropertyInfo property = source.ElementType.GetUltimateShadowingProperty(propertyName); return source.Max(property); } @@ -311,7 +311,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions if (source == null) throw new ArgumentNullException(nameof(source)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - PropertyInfo property = source.ElementType.GetProperty(propertyName); + PropertyInfo property = source.ElementType.GetUltimateShadowingProperty(propertyName); return source.Min(property); } public static object Min(this IQueryable source, PropertyInfo property) @@ -353,8 +353,8 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions if (source == null) throw new ArgumentNullException(nameof(source)); if (averagePropertyName == null) throw new ArgumentNullException(nameof(averagePropertyName)); if (countPropertyName == null) throw new ArgumentNullException(nameof(countPropertyName)); - var averageProperty = source.ElementType.GetProperty(averagePropertyName); - var countProperty = source.ElementType.GetProperty(countPropertyName); + var averageProperty = source.ElementType.GetUltimateShadowingProperty(averagePropertyName); + var countProperty = source.ElementType.GetUltimateShadowingProperty(countPropertyName); return source.AverageWithCount(averageProperty, countProperty, resultType); } public static object AverageWithCount(this IQueryable source, PropertyInfo averageProperty, PropertyInfo countProperty, Type resultType) @@ -431,8 +431,8 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions if (source == null) throw new ArgumentNullException(nameof(source)); if (averagePropertyName == null) throw new ArgumentNullException(nameof(averagePropertyName)); if (sumPropertyName == null) throw new ArgumentNullException(nameof(sumPropertyName)); - var averageProperty = source.ElementType.GetProperty(averagePropertyName); - var sumProperty = source.ElementType.GetProperty(sumPropertyName); + var averageProperty = source.ElementType.GetUltimateShadowingProperty(averagePropertyName); + var sumProperty = source.ElementType.GetUltimateShadowingProperty(sumPropertyName); return source.AverageWithSum(averageProperty, sumProperty, resultType); } public static object AverageWithSum(this IQueryable source, PropertyInfo averageProperty, PropertyInfo sumProperty, Type resultType) diff --git a/src/ShardingCore/Sharding/Visitors/QuerySelectDiscoverVisitor.cs b/src/ShardingCore/Sharding/Visitors/QuerySelectDiscoverVisitor.cs index b74edfd9..34ecbebd 100644 --- a/src/ShardingCore/Sharding/Visitors/QuerySelectDiscoverVisitor.cs +++ b/src/ShardingCore/Sharding/Visitors/QuerySelectDiscoverVisitor.cs @@ -50,7 +50,7 @@ namespace ShardingCore.Core.Internal.Visitors } if (memberExpression.Member.DeclaringType == null) return null; - var fromProperty = memberExpression.Member.DeclaringType.GetProperty(memberExpression.Member.Name); + var fromProperty = memberExpression.Member.DeclaringType.GetUltimateShadowingProperty(memberExpression.Member.Name); return fromProperty; } @@ -68,7 +68,7 @@ namespace ShardingCore.Core.Internal.Visitors { var declaringType = memberExpression.Member.DeclaringType; var memberName = memberExpression.Member.Name; - var propertyInfo = declaringType.GetProperty(memberName); + var propertyInfo = declaringType.GetUltimateShadowingProperty(memberName); _selectContext.SelectProperties.Add(new SelectOwnerProperty(declaringType, propertyInfo)); } @@ -83,7 +83,7 @@ namespace ShardingCore.Core.Internal.Visitors { var declaringType = node.Members[i].DeclaringType; var memberName = node.Members[i].Name; - var propertyInfo = declaringType.GetProperty(memberName); + var propertyInfo = declaringType.GetUltimateShadowingProperty(memberName); if (node.Arguments[i] is MethodCallExpression methodCallExpression) { var method = methodCallExpression.Method; diff --git a/src/ShardingCore/Sharding/Visitors/QueryableExtraDiscoverVisitor.cs b/src/ShardingCore/Sharding/Visitors/QueryableExtraDiscoverVisitor.cs index fe166fe9..125c8e2b 100644 --- a/src/ShardingCore/Sharding/Visitors/QueryableExtraDiscoverVisitor.cs +++ b/src/ShardingCore/Sharding/Visitors/QueryableExtraDiscoverVisitor.cs @@ -89,7 +89,7 @@ namespace ShardingCore.Core.Internal.Visitors if (expression == null) throw new NotSupportedException("sharding order not support "); List properties = new List(); - GetProperty(properties, expression); + GetPropertyInfo(properties, expression); if (!properties.Any()) throw new NotSupportedException("sharding order only support property expression"); properties.Reverse(); @@ -122,7 +122,7 @@ namespace ShardingCore.Core.Internal.Visitors var declaringType = memberExpression.Member.DeclaringType; var memberName = memberExpression.Member.Name; - var propertyInfo = declaringType.GetProperty(memberName); + var propertyInfo = declaringType.GetUltimateShadowingProperty(memberName); _selectContext.SelectProperties.Add(new SelectOwnerProperty(declaringType, propertyInfo)); //memberExpression.Acc }else if (expression is MemberInitExpression memberInitExpression) @@ -135,7 +135,7 @@ namespace ShardingCore.Core.Internal.Visitors { var declaringType = memberBinding.Member.DeclaringType; var memberName = memberBinding.Member.Name; - var propertyInfo = declaringType.GetProperty(memberName); + var propertyInfo = declaringType.GetUltimateShadowingProperty(memberName); _selectContext.SelectProperties.Add(new SelectOwnerProperty(declaringType, propertyInfo)); } } @@ -151,12 +151,12 @@ namespace ShardingCore.Core.Internal.Visitors return base.VisitMethodCall(node); } - private void GetProperty(List properties, MemberExpression memberExpression) + private void GetPropertyInfo(List properties, MemberExpression memberExpression) { properties.Add(memberExpression.Member.Name); if (memberExpression.Expression is MemberExpression member) { - GetProperty(properties, member); + GetPropertyInfo(properties, member); } } diff --git a/src/ShardingCore/ShardingCoreExtension.cs b/src/ShardingCore/ShardingCoreExtension.cs index d4278d7e..fddf34f3 100644 --- a/src/ShardingCore/ShardingCoreExtension.cs +++ b/src/ShardingCore/ShardingCoreExtension.cs @@ -269,16 +269,6 @@ namespace ShardingCore .ReplaceService(); } - - /// - /// 当前接口可以直接移除掉,定时任务会在shardingcore初始化的时候自动调用 - /// - /// - [Obsolete("can remove this method,sharding core auto invoke.")] - public static void UseAutoShardingCreate(this IServiceProvider serviceProvider) - { - } - /// /// 自动尝试补偿表 /// diff --git a/test/ShardingCore.Test/Startup.cs b/test/ShardingCore.Test/Startup.cs index 39b18c36..a9089254 100644 --- a/test/ShardingCore.Test/Startup.cs +++ b/test/ShardingCore.Test/Startup.cs @@ -112,7 +112,6 @@ namespace ShardingCore.Test public void Configure(IServiceProvider serviceProvider) { //启动ShardingCore创建表任务 - serviceProvider.UseAutoShardingCreate(); //启动进行表补偿 serviceProvider.UseAutoTryCompensateTable(); // 有一些测试数据要初始化可以放在这里 diff --git a/test/ShardingCore.Test2x/Startup.cs b/test/ShardingCore.Test2x/Startup.cs index 15f3611e..68e7b486 100644 --- a/test/ShardingCore.Test2x/Startup.cs +++ b/test/ShardingCore.Test2x/Startup.cs @@ -102,7 +102,6 @@ namespace ShardingCore.Test2x // 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法 public void Configure(IServiceProvider serviceProvider) { - serviceProvider.UseAutoShardingCreate(); serviceProvider.UseAutoTryCompensateTable(); // 有一些测试数据要初始化可以放在这里 InitData(serviceProvider).GetAwaiter().GetResult(); diff --git a/test/ShardingCore.Test3x/Startup.cs b/test/ShardingCore.Test3x/Startup.cs index 182c6b22..e0e11612 100644 --- a/test/ShardingCore.Test3x/Startup.cs +++ b/test/ShardingCore.Test3x/Startup.cs @@ -94,7 +94,6 @@ namespace ShardingCore.Test3x // 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法 public void Configure(IServiceProvider serviceProvider) { - serviceProvider.UseAutoShardingCreate(); serviceProvider.UseAutoTryCompensateTable(); // 有一些测试数据要初始化可以放在这里 InitData(serviceProvider).GetAwaiter().GetResult(); diff --git a/test/ShardingCore.Test5x/Startup.cs b/test/ShardingCore.Test5x/Startup.cs index fd9dd077..799acc5d 100644 --- a/test/ShardingCore.Test5x/Startup.cs +++ b/test/ShardingCore.Test5x/Startup.cs @@ -105,7 +105,6 @@ namespace ShardingCore.Test5x // 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法 public void Configure(IServiceProvider serviceProvider) { - serviceProvider.UseAutoShardingCreate(); serviceProvider.UseAutoTryCompensateTable(); // 有一些测试数据要初始化可以放在这里