From 2e15f163f8839c0411e82db89fa8da56f4457b80 Mon Sep 17 00:00:00 2001 From: xuejiaming <326308290@qq.com> Date: Wed, 23 Nov 2022 16:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E9=9C=80=E8=A6=81=E7=9A=84=E7=B1=BB=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShardingCoreBenchmark.csproj | 1 - .../ShardingCoreBenchmark5x.csproj | 1 - .../Sample.AutoCreateIfPresent.csproj | 1 - .../Sample.BulkConsole.csproj | 1 - .../Sample.Migrations.csproj | 1 - .../Sample.MultiConfig.csproj | 1 - samples/Sample.MySql/Sample.MySql.csproj | 1 - .../Sample.NoShardingMultiLevel.csproj | 1 - .../Sample.OracleIssue.csproj | 1 - .../Sample.ShardingConsole.csproj | 1 - .../Sample.SqlServer3x.csproj | 1 - .../Sample.SqlServerShardingAll.csproj | 1 - .../Sample.SqlServerShardingDataSource.csproj | 1 - .../Sample.SqlServerShardingTable.csproj | 1 - .../Samples.AbpSharding.csproj | 1 - .../Querys/QueryEntitiesVisitor2_6.cs | 12 +- .../Visitors/Querys/QueryEntitiesVisitor7.cs | 234 +++++++++--------- src/ShardingCore/ShardingCore.csproj | 1 + src2/ShardingCore2/ShardingCore2.csproj | 1 + src3/ShardingCore3/ShardingCore3.csproj | 1 + src5/ShardingCore5/ShardingCore5.csproj | 1 + src6/ShardingCore6/ShardingCore6.csproj | 1 + .../ShardingCore.CommonTest.csproj | 2 +- .../ShardingCore.Test.csproj | 2 +- .../ShardingCore.Test2x.csproj | 3 +- .../ShardingCore.Test3x.csproj | 3 +- .../ShardingCore.Test5x.csproj | 3 +- .../ShardingCore.Test6x.csproj | 3 +- 28 files changed, 135 insertions(+), 147 deletions(-) diff --git a/benchmarks/ShardingCoreBenchmark/ShardingCoreBenchmark.csproj b/benchmarks/ShardingCoreBenchmark/ShardingCoreBenchmark.csproj index e75f0219..ce2914f0 100644 --- a/benchmarks/ShardingCoreBenchmark/ShardingCoreBenchmark.csproj +++ b/benchmarks/ShardingCoreBenchmark/ShardingCoreBenchmark.csproj @@ -17,7 +17,6 @@ - diff --git a/benchmarks/ShardingCoreBenchmark5x/ShardingCoreBenchmark5x.csproj b/benchmarks/ShardingCoreBenchmark5x/ShardingCoreBenchmark5x.csproj index 2db8b2be..15aa94a4 100644 --- a/benchmarks/ShardingCoreBenchmark5x/ShardingCoreBenchmark5x.csproj +++ b/benchmarks/ShardingCoreBenchmark5x/ShardingCoreBenchmark5x.csproj @@ -12,7 +12,6 @@ - diff --git a/samples/Sample.AutoCreateIfPresent/Sample.AutoCreateIfPresent.csproj b/samples/Sample.AutoCreateIfPresent/Sample.AutoCreateIfPresent.csproj index 758a889a..6efbbf3e 100644 --- a/samples/Sample.AutoCreateIfPresent/Sample.AutoCreateIfPresent.csproj +++ b/samples/Sample.AutoCreateIfPresent/Sample.AutoCreateIfPresent.csproj @@ -13,7 +13,6 @@ - diff --git a/samples/Sample.BulkConsole/Sample.BulkConsole.csproj b/samples/Sample.BulkConsole/Sample.BulkConsole.csproj index 8ed51161..f59d930c 100644 --- a/samples/Sample.BulkConsole/Sample.BulkConsole.csproj +++ b/samples/Sample.BulkConsole/Sample.BulkConsole.csproj @@ -10,7 +10,6 @@ - diff --git a/samples/Sample.Migrations/Sample.Migrations.csproj b/samples/Sample.Migrations/Sample.Migrations.csproj index 35d4cee7..c55466ce 100644 --- a/samples/Sample.Migrations/Sample.Migrations.csproj +++ b/samples/Sample.Migrations/Sample.Migrations.csproj @@ -13,7 +13,6 @@ - diff --git a/samples/Sample.MultiConfig/Sample.MultiConfig.csproj b/samples/Sample.MultiConfig/Sample.MultiConfig.csproj index 9527c7c8..fd48fa03 100644 --- a/samples/Sample.MultiConfig/Sample.MultiConfig.csproj +++ b/samples/Sample.MultiConfig/Sample.MultiConfig.csproj @@ -12,7 +12,6 @@ - diff --git a/samples/Sample.MySql/Sample.MySql.csproj b/samples/Sample.MySql/Sample.MySql.csproj index 311f1cb3..fa192a10 100644 --- a/samples/Sample.MySql/Sample.MySql.csproj +++ b/samples/Sample.MySql/Sample.MySql.csproj @@ -16,7 +16,6 @@ - diff --git a/samples/Sample.NoShardingMultiLevel/Sample.NoShardingMultiLevel.csproj b/samples/Sample.NoShardingMultiLevel/Sample.NoShardingMultiLevel.csproj index 02b7dc9a..e52cc431 100644 --- a/samples/Sample.NoShardingMultiLevel/Sample.NoShardingMultiLevel.csproj +++ b/samples/Sample.NoShardingMultiLevel/Sample.NoShardingMultiLevel.csproj @@ -11,7 +11,6 @@ - diff --git a/samples/Sample.OracleIssue/Sample.OracleIssue.csproj b/samples/Sample.OracleIssue/Sample.OracleIssue.csproj index 505d51d4..2e5a215d 100644 --- a/samples/Sample.OracleIssue/Sample.OracleIssue.csproj +++ b/samples/Sample.OracleIssue/Sample.OracleIssue.csproj @@ -15,7 +15,6 @@ - diff --git a/samples/Sample.ShardingConsole/Sample.ShardingConsole.csproj b/samples/Sample.ShardingConsole/Sample.ShardingConsole.csproj index bde25268..1c52e936 100644 --- a/samples/Sample.ShardingConsole/Sample.ShardingConsole.csproj +++ b/samples/Sample.ShardingConsole/Sample.ShardingConsole.csproj @@ -8,7 +8,6 @@ - diff --git a/samples/Sample.SqlServer3x/Sample.SqlServer3x.csproj b/samples/Sample.SqlServer3x/Sample.SqlServer3x.csproj index 420f0709..8e202344 100644 --- a/samples/Sample.SqlServer3x/Sample.SqlServer3x.csproj +++ b/samples/Sample.SqlServer3x/Sample.SqlServer3x.csproj @@ -9,7 +9,6 @@ - diff --git a/samples/Sample.SqlServerShardingAll/Sample.SqlServerShardingAll.csproj b/samples/Sample.SqlServerShardingAll/Sample.SqlServerShardingAll.csproj index 2023143b..0819f98c 100644 --- a/samples/Sample.SqlServerShardingAll/Sample.SqlServerShardingAll.csproj +++ b/samples/Sample.SqlServerShardingAll/Sample.SqlServerShardingAll.csproj @@ -9,7 +9,6 @@ - diff --git a/samples/Sample.SqlServerShardingDataSource/Sample.SqlServerShardingDataSource.csproj b/samples/Sample.SqlServerShardingDataSource/Sample.SqlServerShardingDataSource.csproj index 05344e28..3a70686b 100644 --- a/samples/Sample.SqlServerShardingDataSource/Sample.SqlServerShardingDataSource.csproj +++ b/samples/Sample.SqlServerShardingDataSource/Sample.SqlServerShardingDataSource.csproj @@ -11,7 +11,6 @@ - diff --git a/samples/Sample.SqlServerShardingTable/Sample.SqlServerShardingTable.csproj b/samples/Sample.SqlServerShardingTable/Sample.SqlServerShardingTable.csproj index 2023143b..0819f98c 100644 --- a/samples/Sample.SqlServerShardingTable/Sample.SqlServerShardingTable.csproj +++ b/samples/Sample.SqlServerShardingTable/Sample.SqlServerShardingTable.csproj @@ -9,7 +9,6 @@ - diff --git a/samples/Samples.AbpSharding/Samples.AbpSharding.csproj b/samples/Samples.AbpSharding/Samples.AbpSharding.csproj index 6162197f..9c902249 100644 --- a/samples/Samples.AbpSharding/Samples.AbpSharding.csproj +++ b/samples/Samples.AbpSharding/Samples.AbpSharding.csproj @@ -11,7 +11,6 @@ - diff --git a/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor2_6.cs b/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor2_6.cs index dc455c37..359f1faa 100644 --- a/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor2_6.cs +++ b/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor2_6.cs @@ -1,4 +1,3 @@ -#if SHARDINGCORE2_6 using System; using System.Collections; using System.Collections.Generic; @@ -18,7 +17,7 @@ namespace ShardingCore.Core.Internal.Visitors.Querys * @Date: Saturday, 20 February 2021 11:14:35 * @Email: 326308290@qq.com */ -#if EFCORE2 || EFCORE3 || NETSTANDARD2_0 +#if EFCORE2 || EFCORE3 /// /// 获取分表类型 /// @@ -115,7 +114,7 @@ namespace ShardingCore.Core.Internal.Visitors.Querys } #endif -#if EFCORE5 || NETSTANDARD2_1 || EFCORE6 +#if EFCORE5|| EFCORE6 || EFCORE7 /// /// 获取分表类型 /// @@ -138,7 +137,11 @@ namespace ShardingCore.Core.Internal.Visitors.Querys { if (node is QueryRootExpression queryRootExpression) { - _shardingEntities.Add(queryRootExpression.EntityType.ClrType); +#if EFCORE7 + _shardingEntities.Add(queryRootExpression.ElementType); +#else + _shardingEntities.Add(queryRootExpression.EntityType.ClrType); +#endif } return base.VisitExtension(node); } @@ -213,4 +216,3 @@ namespace ShardingCore.Core.Internal.Visitors.Querys #endif } -#endif \ No newline at end of file diff --git a/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor7.cs b/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor7.cs index c27c351c..09ee9453 100644 --- a/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor7.cs +++ b/src/ShardingCore/Sharding/Visitors/Querys/QueryEntitiesVisitor7.cs @@ -1,117 +1,117 @@ -#if EFCORE7 -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query; -using ShardingCore.Core.TrackerManagers; -using ShardingCore.Extensions; - -namespace ShardingCore.Core.Internal.Visitors.Querys -{ - /* - * @Author: xjm - * @Description: - * @Date: Saturday, 20 February 2021 11:14:35 - * @Email: 326308290@qq.com - */ - /// - /// 获取分表类型 - /// - internal class QueryEntitiesVisitor : ExpressionVisitor - { - private readonly ITrackerManager _trackerManager; - private readonly ISet _shardingEntities = new HashSet(); - - public QueryEntitiesVisitor(ITrackerManager trackerManager) - { - _trackerManager = trackerManager; - } - - public ISet GetQueryEntities() - { - return _shardingEntities; - } - - protected override Expression VisitExtension(Expression node) - { - if (node is QueryRootExpression queryRootExpression) - { - _shardingEntities.Add(queryRootExpression.ElementType); - } - return base.VisitExtension(node); - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - var methodName = node.Method.Name; - if (methodName == nameof(EntityFrameworkQueryableExtensions.Include) || methodName == nameof(EntityFrameworkQueryableExtensions.ThenInclude)) - { - var genericArguments = node.Type.GetGenericArguments(); - for (var i = 0; i < genericArguments.Length; i++) - { - var genericArgument = genericArguments[i]; - if (typeof(IEnumerable).IsAssignableFrom(genericArgument)) - { - var arguments = genericArgument.GetGenericArguments(); - foreach (var argument in arguments) - { - //if is db context model - if (_trackerManager.IsDbContextModel(argument)) - { - _shardingEntities.Add(argument); - } - } - } - - if (!genericArgument.IsSimpleType()) - { - //if is db context model - if (_trackerManager.IsDbContextModel(genericArgument)) - { - _shardingEntities.Add(genericArgument); - } - } - } - } - return base.VisitMethodCall(node); - } - protected override Expression VisitMember - (MemberExpression memberExpression) - { - // Recurse down to see if we can simplify... - var expression = Visit(memberExpression.Expression); - - // If we've ended up with a constant, and it's a property or a field, - // we can simplify ourselves to a constant - if (expression is ConstantExpression) - { - object container = ((ConstantExpression)expression).Value; - var member = memberExpression.Member; - if (member is FieldInfo fieldInfo) - { - object value = fieldInfo.GetValue(container); - if (value is IQueryable queryable) - { - _shardingEntities.Add(queryable.ElementType); - } - //return Expression.Constant(value); - } - if (member is PropertyInfo propertyInfo) - { - object value = propertyInfo.GetValue(container, null); - if (value is IQueryable queryable) - { - _shardingEntities.Add(queryable.ElementType); - } - } - } - return base.VisitMember(memberExpression); - } - } -} - -#endif \ No newline at end of file +// #if EFCORE7 +// using System; +// using System.Collections; +// using System.Collections.Generic; +// using System.Linq; +// using System.Linq.Expressions; +// using System.Reflection; +// using Microsoft.EntityFrameworkCore; +// using Microsoft.EntityFrameworkCore.Query; +// using ShardingCore.Core.TrackerManagers; +// using ShardingCore.Extensions; +// +// namespace ShardingCore.Core.Internal.Visitors.Querys +// { +// /* +// * @Author: xjm +// * @Description: +// * @Date: Saturday, 20 February 2021 11:14:35 +// * @Email: 326308290@qq.com +// */ +// /// +// /// 获取分表类型 +// /// +// internal class QueryEntitiesVisitor : ExpressionVisitor +// { +// private readonly ITrackerManager _trackerManager; +// private readonly ISet _shardingEntities = new HashSet(); +// +// public QueryEntitiesVisitor(ITrackerManager trackerManager) +// { +// _trackerManager = trackerManager; +// } +// +// public ISet GetQueryEntities() +// { +// return _shardingEntities; +// } +// +// protected override Expression VisitExtension(Expression node) +// { +// if (node is QueryRootExpression queryRootExpression) +// { +// _shardingEntities.Add(queryRootExpression.ElementType); +// } +// return base.VisitExtension(node); +// } +// +// protected override Expression VisitMethodCall(MethodCallExpression node) +// { +// var methodName = node.Method.Name; +// if (methodName == nameof(EntityFrameworkQueryableExtensions.Include) || methodName == nameof(EntityFrameworkQueryableExtensions.ThenInclude)) +// { +// var genericArguments = node.Type.GetGenericArguments(); +// for (var i = 0; i < genericArguments.Length; i++) +// { +// var genericArgument = genericArguments[i]; +// if (typeof(IEnumerable).IsAssignableFrom(genericArgument)) +// { +// var arguments = genericArgument.GetGenericArguments(); +// foreach (var argument in arguments) +// { +// //if is db context model +// if (_trackerManager.IsDbContextModel(argument)) +// { +// _shardingEntities.Add(argument); +// } +// } +// } +// +// if (!genericArgument.IsSimpleType()) +// { +// //if is db context model +// if (_trackerManager.IsDbContextModel(genericArgument)) +// { +// _shardingEntities.Add(genericArgument); +// } +// } +// } +// } +// return base.VisitMethodCall(node); +// } +// protected override Expression VisitMember +// (MemberExpression memberExpression) +// { +// // Recurse down to see if we can simplify... +// var expression = Visit(memberExpression.Expression); +// +// // If we've ended up with a constant, and it's a property or a field, +// // we can simplify ourselves to a constant +// if (expression is ConstantExpression) +// { +// object container = ((ConstantExpression)expression).Value; +// var member = memberExpression.Member; +// if (member is FieldInfo fieldInfo) +// { +// object value = fieldInfo.GetValue(container); +// if (value is IQueryable queryable) +// { +// _shardingEntities.Add(queryable.ElementType); +// } +// //return Expression.Constant(value); +// } +// if (member is PropertyInfo propertyInfo) +// { +// object value = propertyInfo.GetValue(container, null); +// if (value is IQueryable queryable) +// { +// _shardingEntities.Add(queryable.ElementType); +// } +// } +// } +// return base.VisitMember(memberExpression); +// } +// } +// } +// +// #endif \ No newline at end of file diff --git a/src/ShardingCore/ShardingCore.csproj b/src/ShardingCore/ShardingCore.csproj index c3fbd452..7841de39 100644 --- a/src/ShardingCore/ShardingCore.csproj +++ b/src/ShardingCore/ShardingCore.csproj @@ -34,6 +34,7 @@ + diff --git a/src2/ShardingCore2/ShardingCore2.csproj b/src2/ShardingCore2/ShardingCore2.csproj index a6f6c48b..c6e8d3c4 100644 --- a/src2/ShardingCore2/ShardingCore2.csproj +++ b/src2/ShardingCore2/ShardingCore2.csproj @@ -29,6 +29,7 @@ + diff --git a/src3/ShardingCore3/ShardingCore3.csproj b/src3/ShardingCore3/ShardingCore3.csproj index 3c666c8b..eb240a38 100644 --- a/src3/ShardingCore3/ShardingCore3.csproj +++ b/src3/ShardingCore3/ShardingCore3.csproj @@ -29,6 +29,7 @@ + diff --git a/src5/ShardingCore5/ShardingCore5.csproj b/src5/ShardingCore5/ShardingCore5.csproj index 2a7d844f..12872478 100644 --- a/src5/ShardingCore5/ShardingCore5.csproj +++ b/src5/ShardingCore5/ShardingCore5.csproj @@ -31,6 +31,7 @@ + diff --git a/src6/ShardingCore6/ShardingCore6.csproj b/src6/ShardingCore6/ShardingCore6.csproj index dfd01bd8..71c8a7a7 100644 --- a/src6/ShardingCore6/ShardingCore6.csproj +++ b/src6/ShardingCore6/ShardingCore6.csproj @@ -31,6 +31,7 @@ + diff --git a/test/ShardingCore.CommonTest/ShardingCore.CommonTest.csproj b/test/ShardingCore.CommonTest/ShardingCore.CommonTest.csproj index a5a177fe..1525beea 100644 --- a/test/ShardingCore.CommonTest/ShardingCore.CommonTest.csproj +++ b/test/ShardingCore.CommonTest/ShardingCore.CommonTest.csproj @@ -7,7 +7,7 @@ - + all diff --git a/test/ShardingCore.Test/ShardingCore.Test.csproj b/test/ShardingCore.Test/ShardingCore.Test.csproj index 44e42c5e..72ffe503 100644 --- a/test/ShardingCore.Test/ShardingCore.Test.csproj +++ b/test/ShardingCore.Test/ShardingCore.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/test/ShardingCore.Test2x/ShardingCore.Test2x.csproj b/test/ShardingCore.Test2x/ShardingCore.Test2x.csproj index 72624fe2..f64d8834 100644 --- a/test/ShardingCore.Test2x/ShardingCore.Test2x.csproj +++ b/test/ShardingCore.Test2x/ShardingCore.Test2x.csproj @@ -8,7 +8,7 @@ - + @@ -19,7 +19,6 @@ - \ No newline at end of file diff --git a/test/ShardingCore.Test3x/ShardingCore.Test3x.csproj b/test/ShardingCore.Test3x/ShardingCore.Test3x.csproj index 22477b32..50f49c7f 100644 --- a/test/ShardingCore.Test3x/ShardingCore.Test3x.csproj +++ b/test/ShardingCore.Test3x/ShardingCore.Test3x.csproj @@ -8,7 +8,7 @@ - + @@ -18,7 +18,6 @@ - diff --git a/test/ShardingCore.Test5x/ShardingCore.Test5x.csproj b/test/ShardingCore.Test5x/ShardingCore.Test5x.csproj index 65e13ab0..5513a25a 100644 --- a/test/ShardingCore.Test5x/ShardingCore.Test5x.csproj +++ b/test/ShardingCore.Test5x/ShardingCore.Test5x.csproj @@ -9,7 +9,7 @@ - + @@ -20,7 +20,6 @@ - diff --git a/test/ShardingCore.Test6x/ShardingCore.Test6x.csproj b/test/ShardingCore.Test6x/ShardingCore.Test6x.csproj index 6b9f51ea..db46fa0d 100644 --- a/test/ShardingCore.Test6x/ShardingCore.Test6x.csproj +++ b/test/ShardingCore.Test6x/ShardingCore.Test6x.csproj @@ -10,7 +10,7 @@ - + @@ -19,7 +19,6 @@ -