diff --git a/samples/Samples.AbpSharding/AbstractShardingAbpDbContext.cs b/samples/Samples.AbpSharding/AbstractShardingAbpDbContext.cs index 55f6c544..2b7db47b 100644 --- a/samples/Samples.AbpSharding/AbstractShardingAbpDbContext.cs +++ b/samples/Samples.AbpSharding/AbstractShardingAbpDbContext.cs @@ -50,7 +50,7 @@ namespace Samples.AbpSharding if (dbContext is AbpDbContext abpDbContext && abpDbContext.LazyServiceProvider == null) { abpDbContext.LazyServiceProvider = this.LazyServiceProvider; - if (dbContext is IAbpEfCoreDbContext abpEfCoreDbContext) + if (dbContext is IAbpEfCoreDbContext abpEfCoreDbContext&&this.UnitOfWorkManager.Current!=null) { abpEfCoreDbContext.Initialize( new AbpEfCoreDbContextInitializationContext(