Base solution for your next web application
Open Closed

NOT in Filter Multiple Database Context #5404


User avatar
0
maharatha created

I am using multiple database context.

Database 1 - Table Name :Client Database 2 - Table Name : Tenant (This is the abpzero database)

Then I have extended the Tenant table to store Client Id from Table Client to have a mapping between Tenant and Client.

I am creating a drop down which will display clients which are not yet mapped to tenant.

Repository for Client -- _client Repository using ITenantAppService to Get Tenants var tenants = await _tenantAppService.GetTenants(new GetTenantsInput());

once I get the tenants I would like to write a query to only get those clients which have not been mapped with the tenant.

Not able to figure out how to write it.


1 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
    var clientIds = tenants.Select(t => t.ClientId).ToList();
    var clientsWhichHaveNotBeenMappedWithATenant = _clientRepository.GetAll()
        .Where(c => !clientIds.Contains(c.Id))
        .ToList();