-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
5,403 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/EFCore7_8x/ScriptMigrationGenerator.cs → .../EFCore7_8_9x/ScriptMigrationGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Cores/EFCore7_8x/ShardingChangeTracker.cs → ...res/EFCore7_8_9x/ShardingChangeTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
src/ShardingCore/EFCores/EFCore7_8_9x/ShardingMigrator9x.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#if EFCORE9 | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore.Migrations.Internal; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using ShardingCore.Core.RuntimeContexts; | ||
using ShardingCore.Extensions; | ||
using ShardingCore.Helpers; | ||
|
||
namespace ShardingCore.EFCores | ||
{ | ||
public class ShardingMigrator:Migrator | ||
{ | ||
private readonly IShardingRuntimeContext _shardingRuntimeContext; | ||
|
||
public ShardingMigrator(IShardingRuntimeContext shardingRuntimeContext,IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IModelRuntimeInitializer modelRuntimeInitializer, IDiagnosticsLogger<DbLoggerCategory.Migrations> logger, IRelationalCommandDiagnosticsLogger commandLogger, IDatabaseProvider databaseProvider, IMigrationsModelDiffer migrationsModelDiffer, IDesignTimeModel designTimeModel, IDbContextOptions contextOptions, IExecutionStrategy executionStrategy) : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, modelRuntimeInitializer, logger, commandLogger, databaseProvider, migrationsModelDiffer, designTimeModel, contextOptions, executionStrategy) | ||
{ | ||
_shardingRuntimeContext = shardingRuntimeContext; | ||
} | ||
|
||
public override void Migrate(string targetMigration = null) | ||
{ | ||
this.MigrateAsync(targetMigration).WaitAndUnwrapException(false); | ||
// base.Migrate(targetMigration); | ||
} | ||
|
||
public override async Task MigrateAsync(string targetMigration = null, CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
var virtualDataSource = _shardingRuntimeContext.GetVirtualDataSource(); | ||
var allDataSourceNames = virtualDataSource.GetAllDataSourceNames(); | ||
await DynamicShardingHelper.DynamicMigrateWithDataSourcesAsync(_shardingRuntimeContext, allDataSourceNames, null,targetMigration,cancellationToken).ConfigureAwait(false); | ||
|
||
} | ||
|
||
public override string GenerateScript(string fromMigration = null, string toMigration = null, | ||
MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) | ||
{ | ||
return new ScriptMigrationGenerator(_shardingRuntimeContext, fromMigration, toMigration, options).GenerateScript(); | ||
} | ||
} | ||
|
||
} | ||
#endif |
2 changes: 1 addition & 1 deletion
2
...EFCores/EFCore7_8x/ShardingModelSource.cs → ...Cores/EFCore7_8_9x/ShardingModelSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/EFCore7_8x/ShardingOptionsExtension.cs → .../EFCore7_8_9x/ShardingOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if EFCORE7 || EFCORE8 | ||
#if EFCORE7 || EFCORE8 || EFCORE9 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
src/ShardingCore/EFCores/EFCore7_8_9x/ShardingStateManager9x.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#if EFCORE9 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using ShardingCore.Exceptions; | ||
using ShardingCore.Sharding.Abstractions; | ||
|
||
namespace ShardingCore.EFCores | ||
{ | ||
public class ShardingStateManager : StateManager | ||
{ | ||
private readonly IShardingDbContext _currentShardingDbContext; | ||
|
||
public ShardingStateManager(StateManagerDependencies dependencies) : base(dependencies) | ||
{ | ||
_currentShardingDbContext = (IShardingDbContext)Context; | ||
} | ||
|
||
public override InternalEntityEntry GetOrCreateEntry(object entity) | ||
{ | ||
var genericDbContext = _currentShardingDbContext.GetShardingExecutor().CreateGenericDbContext(entity); | ||
var dbContextDependencies = genericDbContext.GetService<IDbContextDependencies>(); | ||
var stateManager = dbContextDependencies.StateManager; | ||
return stateManager.GetOrCreateEntry(entity); | ||
} | ||
|
||
public override InternalEntityEntry GetOrCreateEntry(object entity, IEntityType entityType) | ||
{ | ||
var genericDbContext = _currentShardingDbContext.GetShardingExecutor().CreateGenericDbContext(entity); | ||
var findEntityType = genericDbContext.Model.FindEntityType(entity.GetType()); | ||
var dbContextDependencies = genericDbContext.GetService<IDbContextDependencies>(); | ||
var stateManager = dbContextDependencies.StateManager; | ||
return stateManager.GetOrCreateEntry(entity, findEntityType); | ||
} | ||
|
||
public override InternalEntityEntry StartTrackingFromQuery( | ||
IEntityType baseEntityType, | ||
object entity, | ||
in ISnapshot snapshot) | ||
{ | ||
throw new ShardingCoreNotImplementedException(); | ||
} | ||
|
||
public override InternalEntityEntry TryGetEntry(object entity, bool throwOnNonUniqueness = true) | ||
{ | ||
throw new ShardingCoreNotImplementedException(); | ||
} | ||
|
||
public override InternalEntityEntry TryGetEntry(object entity, IEntityType entityType, | ||
bool throwOnTypeMismatch = true) | ||
{ | ||
throw new ShardingCoreNotImplementedException(); | ||
} | ||
|
||
public override int SaveChanges(bool acceptAllChangesOnSuccess) | ||
{ | ||
//ApplyShardingConcepts(); | ||
int i = 0; | ||
//如果是内部开的事务就内部自己消化 | ||
if (Context.Database.AutoTransactionsEnabled && Context.Database.CurrentTransaction == null && | ||
_currentShardingDbContext.GetShardingExecutor().IsMultiDbContext) | ||
{ | ||
using (var tran = Context.Database.BeginTransaction()) | ||
{ | ||
i = _currentShardingDbContext.GetShardingExecutor().SaveChanges(acceptAllChangesOnSuccess); | ||
tran.Commit(); | ||
} | ||
} | ||
else | ||
{ | ||
i = _currentShardingDbContext.GetShardingExecutor().SaveChanges(acceptAllChangesOnSuccess); | ||
} | ||
|
||
return i; | ||
} | ||
|
||
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, | ||
CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
//ApplyShardingConcepts(); | ||
int i = 0; | ||
//如果是内部开的事务就内部自己消化 | ||
if (Context.Database.AutoTransactionsEnabled && Context.Database.CurrentTransaction == null && | ||
_currentShardingDbContext.GetShardingExecutor().IsMultiDbContext) | ||
{ | ||
using (var tran = await Context.Database.BeginTransactionAsync(cancellationToken)) | ||
{ | ||
i = await _currentShardingDbContext.GetShardingExecutor() | ||
.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); | ||
await tran.CommitAsync(cancellationToken); | ||
} | ||
} | ||
else | ||
{ | ||
i = await _currentShardingDbContext.GetShardingExecutor() | ||
.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); | ||
} | ||
|
||
|
||
return i; | ||
} | ||
} | ||
} | ||
#endif |
2 changes: 1 addition & 1 deletion
2
...FCore7_8x/ShardingWrapOptionsExtension.cs → ...ore7_8_9x/ShardingWrapOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if EFCORE7 || EFCORE8 | ||
#if EFCORE7 || EFCORE8 || EFCORE9 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
2 changes: 1 addition & 1 deletion
2
...e7_8x/Tx/ShardingRelationalTransaction.cs → ..._8_9x/Tx/ShardingRelationalTransaction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...x/ShardingRelationalTransactionFactory.cs → ...x/ShardingRelationalTransactionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...x/ShardingRelationalTransactionManager.cs → ...x/ShardingRelationalTransactionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Core7_8x/UnionAllMergeOptionsExtension.cs → ...re7_8_9x/UnionAllMergeOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if EFCORE7 || EFCORE8 | ||
#if EFCORE7 || EFCORE8 || EFCORE9 | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
Oops, something went wrong.