Open Closed

IRepository / New Props: EntityName, ProviderName #10157


User avatar
0
mgurer created
  • Steps to reproduce the issue: Hello,

I noticed that Abp’s IRepository interface has been updated and now includes two new properties: EntityName and ProviderName.

In my project, I have the following base repository class:

public abstract class ReadOnlyBasicRepositoryBase<TEntity>() : IReadOnlyBasicRepository<TEntity>, IRepository, IServiceProviderAccessor, IUnitOfWorkEnabled where TEntity : class, IEntity { ... }

After the interface change, I had to add the following properties to my implementation:

public string EntityName { get; set; } public string ProviderName { get; }

However, I’m unsure at which point in the repository lifecycle these properties are expected to be initialized. Since I couldn’t find documentation related to this update, I’m not certain how or where these new fields should be populated.

Could you please provide some guidance on the purpose of these properties and how they should be initialized?

Thank you.


4 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • Purpose

      • EntityName: Allows a repository instance to target a named entity when the same CLR type is mapped multiple times (e.g., EF Core Shared-type entity types). Default is null; you only set it in advanced scenarios like working on multiple tables with the same entity class.
      • ProviderName: Exposes the underlying data provider used by the repository: “Volo.Abp.EntityFrameworkCore”, “Volo.Abp.MongoDB”, or “Volo.Abp.MemoryDb”. It’s mainly for internal/diagnostic use; you typically don’t set it yourself.
    • Initialization and usage

      • You do not need to initialize either property in a custom base repository unless you have a specific scenario:
        • EntityName: Leave null by default. If you need it, set it just before using the repository (e.g., in your application/domain service) and then execute queries/commands. Example:
    public class MyService : ApplicationService
          {
              private readonly IRepository<MySharedType, Guid> _repo;
    
              public MyService(IRepository<MySharedType, Guid> repo)
              {
                  _repo = repo;
              }
    
              public async Task<List<MySharedType>> GetFromProductTableAsync()
              {
                  _repo.SetEntityName("Product"); // select the named entity mapping
                  return await _repo.GetListAsync();
              }
          }
    
      Note: The default is null; only set a name if you intentionally mapped the same CLR type as different named entities in your DbContext/model configuration.
    - ProviderName: It’s read-only from consumer perspective (you just read it). The framework sets it in the concrete repository implementation. You can check it when you need provider-specific logic:
    
    if (_repo.ProviderName == Volo.Abp.EntityFrameworkCore.AbpEfCoreConsts.ProviderName)
          {
              // EF Core-specific path
          }
    
    • In custom repository base classes (like your ReadOnlyBasicRepositoryBase<TEntity>):

      • Do not assign ProviderName; allow the specific provider implementation (EF Core/MongoDB/MemoryDb) to supply it.
      • Keep EntityName as null unless your base class implements behavior depending on it. Typically, you won’t set it there; consumers can call SetEntityName(...) before use.
    • Minimal implementation suggestions for your base class

    public abstract class ReadOnlyBasicRepositoryBase<TEntity> :
          IReadOnlyBasicRepository<TEntity>,
          IRepository,
          IServiceProviderAccessor,
          IUnitOfWorkEnabled
          where TEntity : class, IEntity
      {
          // The framework/provider sets this. Expose it as required by the interface.
          public string ProviderName { get; protected set; }
    
          // Default null. Let consumers set it when needed via SetEntityName.
          public string EntityName { get; protected set; }
    
          public virtual void SetEntityName(string entityName)
          {
              EntityName = entityName;
          }
    
          // ...rest of your implementation
      }
    
    • If your interface requires get-only for ProviderName, implement a protected setter or assign it in the provider-specific derived class. For EF Core/Mongo/MemDb repositories supplied by ABP, this is already handled. If you’re implementing a fully custom provider, set ProviderName with your constant provider identifier.

    • When to set them in lifecycle

      • ProviderName: Already initialized by the concrete repository instance when resolved from DI; you just read it.
      • EntityName: Set by the caller right before executing repository methods that depend on a specific named mapping. Otherwise, leave it null.
    1. Sources
    • https://abp.io/docs/latest/framework/architecture/domain-driven-design/repositories
    • https://abp.io/docs/latest/release-notes
    • https://github.com/abpframework/abp

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The EntityName Property

    The EntityName property is to set the related entity's name on the repository object in some advanced scenarios. For example, you can use this property to use the Shared-type entity types feature of Entity Framework Core (it allows you to use a single entity class to work on multiple tables in the database). In other cases, you can just ignore it.

    Default value is null unless you explicitly set it.

    Example usage:

    IRepository&lt;YourSharedType, Guid&gt; _repository; // You can inject it into your class
    ...
    _repository.SetEntityName("Product"); //Set the entity name before using the repository
    //use the _repository object as always
    

    The ProviderName Property

    The ProviderName property of a repository object returns the underlying database provider name. It may return one of the following string values for the built-in providers:

    • Volo.Abp.EntityFrameworkCore (from the constant AbpEfCoreConsts.ProviderName value)
    • Volo.Abp.MongoDB (from the constant AbpMongoDbConsts.ProviderName value)
    • Volo.Abp.MemoryDb (from the constant AbpMemoryDbConsts.ProviderName value)

    This property is not used in most cases. It is mainly available for internal usage of the ABP framework.

    https://github.com/abpframework/abp/pull/23638 https://github.com/abpframework/abp/commit/968bfe0fa037f7cf87c75f8f103043d2cb1f9e30

    Thanks.

  • User Avatar
    0
    mgurer created

    Thanks.

    I updated my base class properties as;

    public string EntityName { get; protected set; }
    public string ProviderName { get => AbpEfCoreConsts.ProviderName; }
    
      public virtual void SetEntityName(string entityName)
      {
          EntityName = entityName;
      }
    

    This will work I guess.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    👍👍👍

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 03, 2025, 13:19
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.