diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs index 1d058d19b9..f85a156184 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs @@ -44,11 +44,11 @@ public abstract class BasicRepositoryBase : public bool? IsChangeTrackingEnabled { get; protected set; } - protected string? CustomEntityName { get; private set; } + protected string? EntityName { get; private set; } - public void SetCustomEntityName(string? name) + public void SetEntityName(string? name) { - CustomEntityName = name; + EntityName = name; } protected BasicRepositoryBase() diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs index c5942088f0..d5a66b1fe7 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs @@ -14,7 +14,7 @@ public interface IRepository { bool? IsChangeTrackingEnabled { get; } - void SetCustomEntityName(string? name); + void SetEntityName(string? name); } public interface IRepository : IReadOnlyRepository, IBasicRepository diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs index 3c43798c38..9fc9c16d31 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryExtensions.cs @@ -250,4 +250,13 @@ public static class RepositoryExtensions hardDeleteEntities.Add(entity); await repository.DeleteAsync(entity, autoSave, cancellationToken); } + + public static TRepository WithEntityName( + this TRepository repository, + string name + ) where TRepository : class, IRepository + { + repository.SetEntityName(name); + return repository; + } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 760660dc82..fd61e72781 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -122,8 +122,8 @@ public class EfCoreRepository : RepositoryBase, IE private DbSet GetDbSetInternal(TDbContext dbContext) { - return CustomEntityName != null - ? dbContext.Set(CustomEntityName) + return EntityName != null + ? dbContext.Set(EntityName) : dbContext.Set(); } diff --git a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index 63aa0e3411..193bbaed14 100644 --- a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -409,7 +409,7 @@ public class RepositoryRegistration_Tests { public bool? IsChangeTrackingEnabled { get; set; } - public void SetCustomEntityName(string name) + public void SetEntityName(string name) { } diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/SharedEntity_Repository_Tests.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/SharedEntity_Repository_Tests.cs index abdc7a4e6d..869069debe 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/SharedEntity_Repository_Tests.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/SharedEntity_Repository_Tests.cs @@ -29,7 +29,7 @@ public class SharedEntity_Repository_Tests : EntityFrameworkCoreTestBase { await WithUnitOfWorkAsync(async () => { - TestSharedTypeEntityRepository.SetCustomEntityName("TestSharedEntity1"); + TestSharedTypeEntityRepository.SetEntityName("TestSharedEntity1"); var tenantId = Guid.NewGuid(); await TestSharedTypeEntityRepository.InsertManyAsync(new List() @@ -121,7 +121,7 @@ public class SharedEntity_Repository_Tests : EntityFrameworkCoreTestBase } } - TestSharedTypeEntityRepository.SetCustomEntityName("TestSharedEntity2"); + TestSharedTypeEntityRepository.SetEntityName("TestSharedEntity2"); await TestSharedTypeEntityRepository.InsertManyAsync(new List() { new TestSharedEntity(Guid.NewGuid()) @@ -146,7 +146,7 @@ public class SharedEntity_Repository_Tests : EntityFrameworkCoreTestBase { await WithUnitOfWorkAsync(async () => { - TestSharedTypeEntityRepository.SetCustomEntityName("TestSharedEntity1"); + TestSharedTypeEntityRepository.SetEntityName("TestSharedEntity1"); var entity = new TestSharedEntity(Guid.NewGuid()) { @@ -169,7 +169,7 @@ public class SharedEntity_Repository_Tests : EntityFrameworkCoreTestBase entity.Birthday.ShouldNotBeNull(); entity["DynamicProperty"].ShouldBe("Test Value1"); - TestSharedTypeEntityRepository.SetCustomEntityName("TestSharedEntity2"); + TestSharedTypeEntityRepository.SetEntityName("TestSharedEntity2"); entity = await TestSharedTypeEntityRepository.FindAsync(x => x.Id == entity.Id!); entity.ShouldBeNull(); });