Open Closed

share an entity that is owned by the host to all tenants #546


User avatar
0
khalid created

ABP Framework version: v3.2.0 UI type: Angular Tiered (MVC) or Identity Server Seperated (Angular): Identity Server Seperated (Angular) Exception message and stack trace: Steps to reproduce the issue:

I have same issue like this How to share an entity that is managed by the host but is accessible by tenants

public class Book: FullAuditedAggregateRoot<Guid>, IMultiTenant
    {
        public virtual Guid? TenantId { get; set; } }

    public string BookName { get; set; }
}

How can  share an entity that is created  by the host to all tenants?

For example a tenant user should be able to see the list of books which is created by  himself and  by host. do I need to add Feature check? if so how?


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    HI,

    This has nothing to do with Feature check, You need to query twice when you are querying the book list. example:

    public async Task<List<BookDto>> GetBooks()
    {
          var result = new List<BookDto>();
          // get the host's books
          using(CurrentTenant.Change(null))
          {
                 result.Add(await BookRepository.ToListAsync());
          }
          
          // get the tenant user's books
          result.Add(await BookRepository.ToListAsync());
    }
    
  • User Avatar
    0
    khalid created

    I got it thanks liangshiwei

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19