diff --git a/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs b/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs
index ff81b29d..a8175a15 100644
--- a/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs
+++ b/samples/Samples.AbpSharding/AbstractShardingAbpZeroDbContext.cs
@@ -43,465 +43,23 @@ namespace Samples.AbpSharding
if (wrapOptionsExtension != null)
{
_shardingDbContextExecutor = new ShardingDbContextExecutor(this);
+ _shardingDbContextExecutor.EntityCreateDbContextBefore += (sender, args) =>
+ {
+ CheckAndSetShardingKeyThatSupportAutoCreate(args.Entity);
+ };
+ _shardingDbContextExecutor.CreateDbContextAfter += (sender, args) =>
+ {
+ var shardingDbContextExecutor = (IShardingDbContextExecutor)sender;
+ var argsDbContext = args.DbContext;
+ var shellDbContext = shardingDbContextExecutor.GetShellDbContext();
+ FillDbContextInject(shellDbContext, argsDbContext);
+ };
}
}
- ///
- /// 是否是真正的执行者
- ///
- protected bool isExecutor => _shardingDbContextExecutor == null;
-
- ///
- /// 路由表
- ///
public IRouteTail RouteTail { get; set; }
-
- public override EntityEntry Add(object entity)
- {
- if (isExecutor)
- base.Add(entity);
- return CreateGenericDbContext(entity).Add(entity);
- }
-
- public override EntityEntry Add(TEntity entity)
- {
- if (isExecutor)
- return base.Add(entity);
- return CreateGenericDbContext(entity).Add(entity);
- }
-
-
- public override ValueTask> AddAsync(TEntity entity, CancellationToken cancellationToken = new CancellationToken())
- {
- if (isExecutor)
- return base.AddAsync(entity, cancellationToken);
- return CreateGenericDbContext(entity).AddAsync(entity, cancellationToken);
- }
-
- public override ValueTask AddAsync(object entity, CancellationToken cancellationToken = new CancellationToken())
- {
- if (isExecutor)
- return base.AddAsync(entity, cancellationToken);
- return CreateGenericDbContext(entity).AddAsync(entity, cancellationToken);
- }
-
- public override void AddRange(params object[] entities)
- {
- if (isExecutor)
- {
- base.AddRange(entities);
- return;
- }
- var groups = entities.Select(o =>
- {
- var dbContext = CreateGenericDbContext(o);
- return new
- {
- DbContext = dbContext,
- Entity = o
- };
- }).GroupBy(g => g.DbContext);
-
- foreach (var group in groups)
- {
- group.Key.AddRange(group.Select(o => o.Entity));
- }
- }
-
- public override void AddRange(IEnumerable