ABP Framework version: v2.9 UI type: Angular Tiered (MVC) or Identity Server Seperated (Angular): no
I have a console application that needs to modify records accross multiple tenants. The console application uses the host admin credentials. I tested out the code below without success:
using (_dataFilter.Disable<IMultiTenant>())
{
var unit = await _unitAppService.GetAsync(Guid.Parse("ED9D4AC2-BC3F-1FA4-71D6-39F5F9048F20"));
Console.WriteLine(unit.UniqueIdentifier);
}
I get the following error:
**Volo.Abp.Http.Client.AbpRemoteCallException: 'There is no entity Unit with id = ed9d4ac2-bc3f-1fa4-71d6-39f5f9048f20!'**
If I change the console application to the tenant's credentials and use ICurrentTenant to change the tenant I can find the record.
Any thoughts on what I am doing wrong?
6 Answer(s)
-
0
Hi,
Because the data is isolated, The host cannot read the tenant's data. If you want read all tenant's data. you can get all tenants and loop get the data. like this:
var tenants = await _tenantRepository.GetListAsync(); foreach (var tenant in tenants) { using (CurrentTenant.Change(tenant.Id)) { var unit = await _unitAppService.GetAsync(Guid.Parse("ED9D4AC2-BC3F-1FA4-71D6-39F5F9048F20")); } }
-
0
Thank you for your quick response. According to one of your earlier responses, I thought that
_dataFilter.Disable<IMultiTenant>()
would achive my goal.[ How to inject a repository to supply all the tenantfull and tenantless records of a database table? #115](https://support.abp.io/QA/Questions/115/How-to-inject-a-repository-to-supply-all-the-tenantfull-and-tenantless-records-of-a-database-table)
When and how is
_dataFilter.Disable<IMultiTenant>()
applied? -
0
Hi.
DataFilter only use shared database. If you use a tenant-separated database, DataFilter is not work.
-
0
I am using a shared database solution. Why did DataFilter not work?
-
0
Volo.Abp.Http.Client.AbpRemoteCallException
I see you are using remote service, You need to disable the multi-tenant filter in the service implementation. like this:
public async Task<Unit> GetAsync(Guid id, bool ignoreTenant = false) { if(ignoreTenant){ using (_dataFilter.Disable<IMultiTenant>()) { //query... } } else{ // query... } }
-
0
Understood, thank you.