添加对.netstandard2.0和.netstandard2.1的支持

This commit is contained in:
xuejiaming 2022-09-29 09:06:30 +08:00
parent 16046d357b
commit c2f14e3a76
24 changed files with 144 additions and 144 deletions

View File

@ -44,9 +44,9 @@ Release | EF Core | .NET | .NET (Core)
Release | .NET (Core) Release | .NET (Core)
--- | --- --- | ---
[6.x.x.x](https://www.nuget.org/packages/ShardingCore) | 6.0 [6.x.x.x](https://www.nuget.org/packages/ShardingCore) | net6
[5.x.x.x](https://www.nuget.org/packages/ShardingCore) | 5.0 [5.x.x.x](https://www.nuget.org/packages/ShardingCore) | net5 or netstandard2.1
[3.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp3 [3.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp3 or netstandard2.0
[2.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp2 [2.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp2

View File

@ -43,9 +43,9 @@ Use Condition Compile With NetFramework not
Release | .NET (Core) Release | .NET (Core)
--- | --- --- | ---
[6.x.x.x](https://www.nuget.org/packages/ShardingCore) | 6.0 [6.x.x.x](https://www.nuget.org/packages/ShardingCore) | net6
[5.x.x.x](https://www.nuget.org/packages/ShardingCore) | 5.0 [5.x.x.x](https://www.nuget.org/packages/ShardingCore) | net5 or netstandard2.1
[3.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp3 [3.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp3 or netstandard2.0
[2.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp2 [2.x.x.x](https://www.nuget.org/packages/ShardingCore) | netcoreapp2
## Quick start ## Quick start

View File

@ -20,7 +20,7 @@ namespace ShardingCore.EFCores.ChangeTrackers
_dbContext = context; _dbContext = context;
} }
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
@ -122,7 +122,7 @@ namespace ShardingCore.EFCores.ChangeTrackers
} }
#endif #endif
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 #if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_0
public override void Clear() public override void Clear()
{ {
if (_dbContext is IShardingDbContext) if (_dbContext is IShardingDbContext)

View File

@ -1,4 +1,4 @@
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NETSTANDARD2_0
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using ShardingCore.Core.RuntimeContexts; using ShardingCore.Core.RuntimeContexts;

View File

@ -1,4 +1,4 @@
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,4 +1,4 @@
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using ShardingCore.Core.RuntimeContexts; using ShardingCore.Core.RuntimeContexts;

View File

@ -1,4 +1,4 @@
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;

View File

@ -14,7 +14,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
* @Ver: 1.0 * @Ver: 1.0
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
@ -63,7 +63,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
} }
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public class ShardingOptionsExtension: IDbContextOptionsExtension public class ShardingOptionsExtension: IDbContextOptionsExtension
{ {
public IShardingRuntimeContext ShardingRuntimeContext { get; } public IShardingRuntimeContext ShardingRuntimeContext { get; }

View File

@ -15,7 +15,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
#if NET6_0 #if NET6_0
@ -55,7 +55,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
} }
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public class ShardingWrapOptionsExtension: IDbContextOptionsExtension public class ShardingWrapOptionsExtension: IDbContextOptionsExtension
{ {

View File

@ -14,7 +14,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
#if NET6_0 #if NET6_0
@ -50,7 +50,7 @@ namespace ShardingCore.EFCores.OptionsExtensions
} }
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public class UnionAllMergeOptionsExtension: IDbContextOptionsExtension public class UnionAllMergeOptionsExtension: IDbContextOptionsExtension
{ {

View File

@ -20,7 +20,7 @@ namespace ShardingCore.EFCores
* @Ver: 1.0 * @Ver: 1.0
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
public class ShardingRelationalTransaction : RelationalTransaction public class ShardingRelationalTransaction : RelationalTransaction
@ -34,7 +34,7 @@ namespace ShardingCore.EFCores
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public ShardingRelationalTransaction(IShardingDbContext shardingDbContext, IRelationalConnection connection, public ShardingRelationalTransaction(IShardingDbContext shardingDbContext, IRelationalConnection connection,
DbTransaction transaction, Guid transactionId, DbTransaction transaction, Guid transactionId,
IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> logger, bool transactionOwned) : base(connection, IDiagnosticsLogger<DbLoggerCategory.Database.Transaction> logger, bool transactionOwned) : base(connection,

View File

@ -12,10 +12,10 @@ namespace ShardingCore.EFCores
* @Date: Saturday, 14 August 2021 10:17:43 * @Date: Saturday, 14 August 2021 10:17:43
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
#if NET5_0 || NET6_0 #if NET5_0 || NETSTANDARD2_1 || NET6_0
public class ShardingDbSetSource : IDbSetSource public class ShardingDbSetSource : IDbSetSource
{ {
@ -55,7 +55,7 @@ namespace ShardingCore.EFCores
=> (c, name) => new ShardingInternalDbSet<TEntity>(c, name); => (c, name) => new ShardingInternalDbSet<TEntity>(c, name);
} }
#endif #endif
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0
public class ShardingDbSetSource:IDbSetSource public class ShardingDbSetSource:IDbSetSource
{ {

View File

@ -26,7 +26,7 @@ namespace ShardingCore.EFCores
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
public class ShardingInternalDbSet<TEntity> : InternalDbSet<TEntity> public class ShardingInternalDbSet<TEntity> : InternalDbSet<TEntity>
@ -36,7 +36,7 @@ namespace ShardingCore.EFCores
private readonly IShardingRuntimeContext _shardingRuntimeContext; private readonly IShardingRuntimeContext _shardingRuntimeContext;
private LocalView<TEntity>? _localView; private LocalView<TEntity>? _localView;
#if NET5_0 || NET6_0 #if NET5_0 || NETSTANDARD2_1 || NET6_0
public ShardingInternalDbSet(DbContext context, string entityTypeName) : base(context, entityTypeName) public ShardingInternalDbSet(DbContext context, string entityTypeName) : base(context, entityTypeName)
{ {
@ -44,7 +44,7 @@ namespace ShardingCore.EFCores
_shardingRuntimeContext = context.GetShardingRuntimeContext(); _shardingRuntimeContext = context.GetShardingRuntimeContext();
} }
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0
public ShardingInternalDbSet(DbContext context) : base(context) public ShardingInternalDbSet(DbContext context) : base(context)
{ {
_context = (IShardingDbContext)context; _context = (IShardingDbContext)context;

View File

@ -35,7 +35,7 @@ namespace ShardingCore.EFCores
{ {
private readonly IShardingRuntimeContext _shardingRuntimeContext; private readonly IShardingRuntimeContext _shardingRuntimeContext;
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
@ -46,14 +46,14 @@ namespace ShardingCore.EFCores
} }
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
public ShardingMigrator(IShardingRuntimeContext shardingRuntimeContext, IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IConventionSetBuilder conventionSetBuilder, IDiagnosticsLogger<DbLoggerCategory.Migrations> logger, IDiagnosticsLogger<DbLoggerCategory.Database.Command> commandLogger, IDatabaseProvider databaseProvider) : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, conventionSetBuilder, logger, commandLogger, databaseProvider) public ShardingMigrator(IShardingRuntimeContext shardingRuntimeContext, IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IConventionSetBuilder conventionSetBuilder, IDiagnosticsLogger<DbLoggerCategory.Migrations> logger, IDiagnosticsLogger<DbLoggerCategory.Database.Command> commandLogger, IDatabaseProvider databaseProvider) : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, conventionSetBuilder, logger, commandLogger, databaseProvider)
{ {
_shardingRuntimeContext = shardingRuntimeContext; _shardingRuntimeContext = shardingRuntimeContext;
} }
#endif #endif
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0
public ShardingMigrator(IShardingRuntimeContext shardingRuntimeContext, IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IDiagnosticsLogger<DbLoggerCategory.Migrations> logger, IDiagnosticsLogger<DbLoggerCategory.Database.Command> commandLogger, IDatabaseProvider databaseProvider) : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, logger, commandLogger, databaseProvider) public ShardingMigrator(IShardingRuntimeContext shardingRuntimeContext, IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IDiagnosticsLogger<DbLoggerCategory.Migrations> logger, IDiagnosticsLogger<DbLoggerCategory.Database.Command> commandLogger, IDatabaseProvider databaseProvider) : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, logger, commandLogger, databaseProvider)
{ {
_shardingRuntimeContext = shardingRuntimeContext; _shardingRuntimeContext = shardingRuntimeContext;
@ -81,7 +81,7 @@ namespace ShardingCore.EFCores
await DynamicShardingHelper.DynamicMigrateWithDataSourcesAsync(_shardingRuntimeContext, allDataSourceNames, null,cancellationToken); await DynamicShardingHelper.DynamicMigrateWithDataSourcesAsync(_shardingRuntimeContext, allDataSourceNames, null,cancellationToken);
} }
#if NET6_0 || NET5_0 #if NET6_0 || NET5_0 || NETSTANDARD2_1
public override string GenerateScript(string fromMigration = null, string toMigration = null, public override string GenerateScript(string fromMigration = null, string toMigration = null,
MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default)
@ -89,7 +89,7 @@ namespace ShardingCore.EFCores
return new ScriptMigrationGenerator(_shardingRuntimeContext, fromMigration, toMigration, options).GenerateScript(); return new ScriptMigrationGenerator(_shardingRuntimeContext, fromMigration, toMigration, options).GenerateScript();
} }
#endif #endif
#if NETCOREAPP3_0 || NETCOREAPP2_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NETCOREAPP2_0
public override string GenerateScript(string fromMigration = null, string toMigration = null, bool idempotent = false) public override string GenerateScript(string fromMigration = null, string toMigration = null, bool idempotent = false)
{ {
return new ScriptMigrationGenerator(_shardingRuntimeContext, fromMigration, toMigration, idempotent).GenerateScript(); return new ScriptMigrationGenerator(_shardingRuntimeContext, fromMigration, toMigration, idempotent).GenerateScript();

View File

@ -18,7 +18,7 @@ namespace ShardingCore.EFCores
* @Ver: 1.0 * @Ver: 1.0
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
#if NET6_0 #if NET6_0
@ -38,7 +38,7 @@ namespace ShardingCore.EFCores
} }
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public class ShardingRelationalTransactionFactory<TShardingDbContext> : RelationalTransactionFactory where TShardingDbContext : DbContext, IShardingDbContext public class ShardingRelationalTransactionFactory<TShardingDbContext> : RelationalTransactionFactory where TShardingDbContext : DbContext, IShardingDbContext
{ {

View File

@ -112,7 +112,7 @@ namespace ShardingCore.EFCores
_shardingDbContext.NotifyShardingTransaction(); _shardingDbContext.NotifyShardingTransaction();
return dbContextTransaction; return dbContextTransaction;
} }
#if !NETCOREAPP3_0 #if !NETCOREAPP3_0 && !NETSTANDARD2_0
public Task CommitTransactionAsync(CancellationToken cancellationToken = new CancellationToken()) public Task CommitTransactionAsync(CancellationToken cancellationToken = new CancellationToken())
{ {

View File

@ -32,14 +32,14 @@ namespace ShardingCore.Extensions
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public static void RemoveDbContextRelationModelThatIsShardingTable(this DbContext dbContext) public static void RemoveDbContextRelationModelThatIsShardingTable(this DbContext dbContext)
{ {
#if !NETCOREAPP2_0&&!NETCOREAPP3_0&&!NET5_0&&!NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
throw new NotImplementedException(); throw new NotImplementedException();
#endif #endif
#if NET6_0 #if NET6_0
var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ; var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ;
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 || NET5_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0 || NET5_0 || NETSTANDARD2_1
var contextModel = dbContext.Model as Model; var contextModel = dbContext.Model as Model;
#endif #endif
@ -55,7 +55,7 @@ namespace ShardingCore.Extensions
contextModelRelationalModel.Tables.Remove(valueTuples[i]); contextModelRelationalModel.Tables.Remove(valueTuples[i]);
} }
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel; var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
var valueTuples = var valueTuples =
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => entityMetadataManager.IsShardingTable(m.EntityType.ClrType))).Select(o => o.Key).ToList(); contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => entityMetadataManager.IsShardingTable(m.EntityType.ClrType))).Select(o => o.Key).ToList();
@ -64,7 +64,7 @@ namespace ShardingCore.Extensions
contextModelRelationalModel.Tables.Remove(valueTuples[i]); contextModelRelationalModel.Tables.Remove(valueTuples[i]);
} }
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0
var entityTypes = var entityTypes =
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>; contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
var list = entityTypes.Where(o=>entityMetadataManager.IsShardingTable(o.Value.ClrType)).Select(o=>o.Key).ToList(); var list = entityTypes.Where(o=>entityMetadataManager.IsShardingTable(o.Value.ClrType)).Select(o=>o.Key).ToList();
@ -109,14 +109,14 @@ namespace ShardingCore.Extensions
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public static void RemoveDbContextAllRelationModelWithoutShardingDataSourceOnly(this DbContext dbContext) public static void RemoveDbContextAllRelationModelWithoutShardingDataSourceOnly(this DbContext dbContext)
{ {
#if !NETCOREAPP2_0&&!NETCOREAPP3_0&&!NET5_0&&!NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
throw new NotImplementedException(); throw new NotImplementedException();
#endif #endif
#if NET6_0 #if NET6_0
var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ; var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ;
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 || NET5_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
var contextModel = dbContext.Model as Model; var contextModel = dbContext.Model as Model;
#endif #endif
@ -132,7 +132,7 @@ namespace ShardingCore.Extensions
contextModelRelationalModel.Tables.Remove(valueTuples[i]); contextModelRelationalModel.Tables.Remove(valueTuples[i]);
} }
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel; var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
var valueTuples = var valueTuples =
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => !entityMetadataManager.IsShardingDataSource(m.EntityType.ClrType)||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList(); contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => !entityMetadataManager.IsShardingDataSource(m.EntityType.ClrType)||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList();
@ -141,7 +141,7 @@ namespace ShardingCore.Extensions
contextModelRelationalModel.Tables.Remove(valueTuples[i]); contextModelRelationalModel.Tables.Remove(valueTuples[i]);
} }
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0
var entityTypes = var entityTypes =
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>; contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
var list = entityTypes.Where(o => !entityMetadataManager.IsShardingDataSource(o.Value.ClrType) || entityMetadataManager.TryGet(o.Value.ClrType) == null).Select(o => o.Key).ToList(); var list = entityTypes.Where(o => !entityMetadataManager.IsShardingDataSource(o.Value.ClrType) || entityMetadataManager.TryGet(o.Value.ClrType) == null).Select(o => o.Key).ToList();
@ -157,14 +157,14 @@ namespace ShardingCore.Extensions
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public static void RemoveDbContextAllRelationModel(this DbContext dbContext) public static void RemoveDbContextAllRelationModel(this DbContext dbContext)
{ {
#if !NETCOREAPP2_0&&!NETCOREAPP3_0&&!NET5_0&&!NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
throw new NotImplementedException(); throw new NotImplementedException();
#endif #endif
#if NET6_0 #if NET6_0
var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ; var contextModel = dbContext.GetService<IDesignTimeModel>().Model; ;
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 || NET5_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
var contextModel = dbContext.Model as Model; var contextModel = dbContext.Model as Model;
#endif #endif
@ -173,11 +173,11 @@ namespace ShardingCore.Extensions
var contextModelRelationalModel = contextModel.GetRelationalModel() as RelationalModel; var contextModelRelationalModel = contextModel.GetRelationalModel() as RelationalModel;
contextModelRelationalModel.Tables.Clear(); contextModelRelationalModel.Tables.Clear();
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel; var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
contextModelRelationalModel.Tables.Clear(); contextModelRelationalModel.Tables.Clear();
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0
var entityTypes = var entityTypes =
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>; contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
entityTypes.Clear(); entityTypes.Clear();
@ -192,10 +192,10 @@ namespace ShardingCore.Extensions
public static void RemoveDbContextRelationModelSaveOnlyThatIsNamedType(this DbContext dbContext, public static void RemoveDbContextRelationModelSaveOnlyThatIsNamedType(this DbContext dbContext,
Type shardingType) Type shardingType)
{ {
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
1 1
#endif #endif
#if NETCOREAPP2_0 ||NETCOREAPP3_0 ||NET5_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0 ||NET5_0 || NETSTANDARD2_1
var contextModel = dbContext.Model as Model; var contextModel = dbContext.Model as Model;
#endif #endif
@ -220,7 +220,7 @@ namespace ShardingCore.Extensions
} }
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel; var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
var entityTypes = contextModel.GetEntityTypes(); var entityTypes = contextModel.GetEntityTypes();
@ -239,7 +239,7 @@ namespace ShardingCore.Extensions
contextModelRelationalModel.Tables.Remove(valueTuples[i]); contextModelRelationalModel.Tables.Remove(valueTuples[i]);
} }
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0
var entityTypes = var entityTypes =
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>; contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
@ -270,7 +270,7 @@ namespace ShardingCore.Extensions
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public static void RemoveModelCache(this DbContext dbContext) public static void RemoveModelCache(this DbContext dbContext)
{ {
#if !NETCOREAPP2_0&&!NETCOREAPP3_0&&!NET5_0&&!NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
throw new NotImplementedException(); throw new NotImplementedException();
#endif #endif
#if NET6_0 #if NET6_0
@ -281,13 +281,13 @@ namespace ShardingCore.Extensions
object key2 = modelCacheKeyFactory.Create(dbContext,false); object key2 = modelCacheKeyFactory.Create(dbContext,false);
shardingModelSource.Remove(key2); shardingModelSource.Remove(key2);
#endif #endif
#if NET5_0 #if NET5_0 || NETSTANDARD2_1
var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource; var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory(); var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();
object key1 = modelCacheKeyFactory.Create(dbContext); object key1 = modelCacheKeyFactory.Create(dbContext);
shardingModelSource.Remove(key1); shardingModelSource.Remove(key1);
#endif #endif
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0
var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource; var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory(); var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();

View File

@ -16,7 +16,7 @@ namespace ShardingCore.Extensions
//public static void ForEach<T>(this IEnumerable<T> source) //public static void ForEach<T>(this IEnumerable<T> source)
#if !NET5_0 #if !NET5_0 || NETSTANDARD2_1
public static HashSet<TSource> ToHashSet<TSource>( public static HashSet<TSource> ToHashSet<TSource>(
this IEnumerable<TSource> source, this IEnumerable<TSource> source,
IEqualityComparer<TSource> comparer = null) IEqualityComparer<TSource> comparer = null)

View File

@ -30,7 +30,7 @@ namespace ShardingCore.Sharding.Enumerators.StreamMergeAsync
_moveIndex++; _moveIndex++;
return HasElement(); return HasElement();
} }
#if !NETCOREAPP2_0&&!NETCOREAPP3_0&&!NET5_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NET5_0 && !NETSTANDARD2_1
public ValueTask DisposeAsync() public ValueTask DisposeAsync()
{ {
return ValueTask.CompletedTask; return ValueTask.CompletedTask;
@ -46,7 +46,7 @@ namespace ShardingCore.Sharding.Enumerators.StreamMergeAsync
} }
#endif #endif
#if NETCOREAPP3_0 || NET5_0 #if NETCOREAPP3_0 || NETSTANDARD2_0 || NET5_0 || NETSTANDARD2_1
public ValueTask DisposeAsync() public ValueTask DisposeAsync()
{ {
return new ValueTask(); return new ValueTask();

View File

@ -23,7 +23,7 @@ namespace ShardingCore.Sharding.Parsers.Visitors
/// Author: xjm /// Author: xjm
/// Created: 2022/5/1 21:43:12 /// Created: 2022/5/1 21:43:12
/// Email: 326308290@qq.com /// Email: 326308290@qq.com
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
internal class ShardingQueryPrepareVisitor : ExpressionVisitor internal class ShardingQueryPrepareVisitor : ExpressionVisitor
@ -57,7 +57,7 @@ namespace ShardingCore.Sharding.Parsers.Visitors
shardingQueryableAsSequenceOptions, shardingQueryableAsSequenceOptions,
shardingEntities, isNoTracking, isIgnoreFilter); shardingEntities, isNoTracking, isIgnoreFilter);
} }
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP3_0
protected override Expression VisitConstant(ConstantExpression node) protected override Expression VisitConstant(ConstantExpression node)
{ {
if (node.Value is IQueryable queryable) if (node.Value is IQueryable queryable)
@ -68,7 +68,7 @@ namespace ShardingCore.Sharding.Parsers.Visitors
return base.VisitConstant(node); return base.VisitConstant(node);
} }
#endif #endif
#if NET5_0 || NET6_0 #if NET5_0 || NETSTANDARD2_1 || NET6_0
protected override Expression VisitExtension(Expression node) protected override Expression VisitExtension(Expression node)
{ {
if (node is QueryRootExpression queryRootExpression) if (node is QueryRootExpression queryRootExpression)

View File

@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.Internal;
#if NETCOREAPP3_0 #if NETCOREAPP3_0 || NETSTANDARD2_0
using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.Internal;
#endif #endif

View File

@ -153,7 +153,7 @@ namespace ShardingCore.Core.Internal.Visitors
} }
} }
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0
internal class DbContextReplaceQueryableVisitor : DbContextInnerMemberReferenceReplaceQueryableVisitor internal class DbContextReplaceQueryableVisitor : DbContextInnerMemberReferenceReplaceQueryableVisitor
{ {
private readonly DbContext _dbContext; private readonly DbContext _dbContext;
@ -193,7 +193,7 @@ namespace ShardingCore.Core.Internal.Visitors
} }
#endif #endif
#if NET5_0 || NET6_0 #if NET5_0 || NETSTANDARD2_1 || NET6_0
internal class DbContextReplaceQueryableVisitor : DbContextInnerMemberReferenceReplaceQueryableVisitor internal class DbContextReplaceQueryableVisitor : DbContextInnerMemberReferenceReplaceQueryableVisitor
{ {
private readonly DbContext _dbContext; private readonly DbContext _dbContext;

View File

@ -17,10 +17,10 @@ namespace ShardingCore.Core.Internal.Visitors.Querys
* @Date: Saturday, 20 February 2021 11:14:35 * @Date: Saturday, 20 February 2021 11:14:35
* @Email: 326308290@qq.com * @Email: 326308290@qq.com
*/ */
#if !NETCOREAPP2_0 && !NETCOREAPP3_0 && !NET5_0 && !NET6_0 #if !NETCOREAPP2_0 && !NETSTANDARD2_0 && !NETCOREAPP3_0 && !NETSTANDARD2_1 && !NET5_0 && !NET6_0
error error
#endif #endif
#if NETCOREAPP2_0 || NETCOREAPP3_0 #if NETCOREAPP2_0 || NETCOREAPP3_0 || NETSTANDARD2_0
/// <summary> /// <summary>
/// 获取分表类型 /// 获取分表类型
/// </summary> /// </summary>
@ -117,7 +117,7 @@ namespace ShardingCore.Core.Internal.Visitors.Querys
} }
#endif #endif
#if NET5_0 || NET6_0 #if NET5_0 || NETSTANDARD2_1 || NET6_0
/// <summary> /// <summary>
/// 获取分表类型 /// 获取分表类型
/// </summary> /// </summary>

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netcoreapp2;netcoreapp3;net5;net6</TargetFrameworks> <TargetFrameworks>netcoreapp2;netcoreapp3;netstandard2.0;netstandard2.1;net5;net6</TargetFrameworks>
<Version>$(SHARDINGCORE)</Version> <Version>$(SHARDINGCORE)</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;</DefineConstants> <DefineConstants>TRACE;DEBUG;</DefineConstants>
@ -13,13 +13,13 @@
<DocumentationFile>bin\Release\ShardingCore.2x.xml</DocumentationFile> <DocumentationFile>bin\Release\ShardingCore.2x.xml</DocumentationFile>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' and '$(TargetFramework)' == 'netcoreapp3'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' and ('$(TargetFramework)' == 'netcoreapp3' or '$(TargetFramework)' == 'netstandard2.0')">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\Release\ShardingCore.3x.xml</DocumentationFile> <DocumentationFile>bin\Release\ShardingCore.3x.xml</DocumentationFile>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' and '$(TargetFramework)' == 'net5'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU' and ('$(TargetFramework)' == 'net5' or '$(TargetFramework)' == 'netstandard2.1')">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\Release\ShardingCore.5x.xml</DocumentationFile> <DocumentationFile>bin\Release\ShardingCore.5x.xml</DocumentationFile>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
@ -61,12 +61,12 @@
<NoWarn>1701;1702;1591;</NoWarn> <NoWarn>1701;1702;1591;</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Core\VirtualRoutes\RouteConditions\**" /> <Compile Remove="Core\VirtualRoutes\RouteConditions\**"/>
<Compile Remove="Sharding\Abstractions\MergeParseContexts\**" /> <Compile Remove="Sharding\Abstractions\MergeParseContexts\**"/>
<EmbeddedResource Remove="Core\VirtualRoutes\RouteConditions\**" /> <EmbeddedResource Remove="Core\VirtualRoutes\RouteConditions\**"/>
<EmbeddedResource Remove="Sharding\Abstractions\MergeParseContexts\**" /> <EmbeddedResource Remove="Sharding\Abstractions\MergeParseContexts\**"/>
<None Remove="Core\VirtualRoutes\RouteConditions\**" /> <None Remove="Core\VirtualRoutes\RouteConditions\**"/>
<None Remove="Sharding\Abstractions\MergeParseContexts\**" /> <None Remove="Sharding\Abstractions\MergeParseContexts\**"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\Logo\logo.png"> <None Include="..\..\Logo\logo.png">
@ -75,22 +75,22 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2'"> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.*"/>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3'"> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3' or '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.*"/>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5'"> <ItemGroup Condition="'$(TargetFramework)' == 'net5' or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.*"/>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6'"> <ItemGroup Condition="'$(TargetFramework)' == 'net6'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.*" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.*"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Sharding\Visitors\GroupBys" /> <Folder Include="Sharding\Visitors\GroupBys"/>
</ItemGroup> </ItemGroup>
</Project> </Project>