Open Closed

IgnoreMultiTenancy, May I use IgnoreMultiTenancy on a single query action? #2689


User avatar
0
zhongfang created

I found this attribute in TenantManagementDbContext. I want to use this function, ignore TenantId in a single query, not whole DbContext, How to do?

using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.MultiTenancy;

namespace Volo.Abp.TenantManagement.EntityFrameworkCore;

[IgnoreMultiTenancy]
[ConnectionStringName(AbpTenantManagementDbProperties.ConnectionStringName)]
public class TenantManagementDbContext : AbpDbContext<TenantManagementDbContext>, ITenantManagementDbContext
{
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    zhongfang created
    private readonly IRepository<Product, Guid> _productRepository;
            private readonly IDataFilter _dataFilter;
    
            public ProductManager(
                IRepository<Product, Guid> productRepository,
                IDataFilter dataFilter)
            {
                _productRepository = productRepository;
                _dataFilter = dataFilter;
            }
    
            public async Task<long> GetProductCountAsync()
            {
                using (_dataFilter.Disable<IMultiTenant>())
                {
                    return await _productRepository.GetCountAsync();
                }
            }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.