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
{

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();
                }
            }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35