Open Closed

Design Considerations: Querying all tenant data #1504


User avatar
0
davidc@educlarity.com created

Greetings;

Say for example i have this business case:

I have a service based business. I want my tenants to be able to submit a work request to me (the application owner). I want to be able to design a UI such that I can see all of these requests (from all tenants) in one location, and manage them from one central location.

Questions: Can you talk about any design considerations for this scenario? Should the ServiceRequest entity be designed any differently than a normal entity? Another quick side question: I come from the aspnetzero world where there is IMayHaveTenant: does this exist within ABP?

Many thanks,

--Dave

ps: If anybody else out there is/has worked with this scenario, I'd appreciate any of your issues and resolutions too!


3 Answer(s)
  • User Avatar
    0
    davidc@educlarity.com created

    I think I may have answered my own question here.. But I'd appreciate any feedback on this:

    https://docs.abp.io/en/abp/latest/Data-Filtering

    Adapted from the link above. Disable the IMulitiTenant data filter.

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Volo.Abp;
    using Volo.Abp.Data;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Domain.Repositories;
    
    namespace Acme.BookStore
    {
        public class MyBookService : ITransientDependency
        {
            private readonly IDataFilter _dataFilter;
            private readonly IRepository<Book, Guid> _bookRepository;
    
            public MyBookService(
                IDataFilter dataFilter,
                IRepository<Book, Guid> bookRepository)
            {
                _dataFilter = dataFilter;
                _bookRepository = bookRepository;
            }
    
            public async Task<List<Book>> GetAllBooksForAllTenantsAsync()
            {
                //Temporary disable the IMultitenant filter
                using (_dataFilter.Disable<IMultiTenant>())
                {
                    return await _bookRepository.GetListAsync();
                }
            }
        }
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    https://docs.abp.io/en/abp/latest/Data-Filtering, just work for a single database.

    If a tenant has own database, you need to query all tenants, and then switch each tenant.

    example:

    
    var tenants = await _tenantRepository.GetListAsync();
    
    foreach(var tenant in tenants)
    {
        using(CurrentTenant.Change(tenant.Id))
        {
            var books = await _bookRepository.GetListAsync();
        }
    }
    
    
  • User Avatar
    0
    davidc@educlarity.com created

    Ok.. Thank you. I will close this ticket.

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 v9.3.0-preview. Updated on May 15, 2025, 10:28