Hi,
I have a set of data that is stored per Tenant.
When I logging in under Host Admin, I try to access that data, I set this:
List<Shelter> shelters;
shelters = await _shelters.Shelters.OrderBy(s => s.ShelterCode).ToListAsync();
I get all the data. The data is all stored with a TenantId = 1.
So, when I am logging in as Admin Host, the tenant Id should be null.
How come the data is retrieved?
Am I missing something here?
This is the WHERE clause in SQL after using SQL Profiler:
WHERE
(
([TenantId] = 0) OR ( CAST( [TenantId] AS int) IS NULL) OR (1 IS NOT NULL)
) AND
(([IsDeleted] = 0) )
1 IS NOT NULL always true, hence all data are returned. But why do I have that additional filter?
Thanks Bilal
5 Answer(s)
-
0
Hi,
Can you share your entity definition, a screenshot of sample data and code for you app service ?
Thanks.
-
0
Sure, here you go.
Entity (.Core)
AppService (.Application)
Seed method (.EntityFramework)
Table in DB (<a class="postlink" href="https://s21.postimg.org/ra51m36lz/image.png">https://s21.postimg.org/ra51m36lz/image.png</a>)
In a common lookup AppService I use this code:
public async Task<ReferenceDataDto> GetReferenceTables() { // Bring Shelters from specific Tenant user is logged in to List<Shelter> shelters; shelters = await _shelters.Shelters.OrderBy(s => s.ShelterCode).ToListAsync();
This AppService I was calling while logged in as Admin Host.
Appreciate your assistance.
-
0
-
0
Hi,
Normally you don't need SetTenantId. Can you share the code for getting _manager.Shelters in GetShelters method ?
Thanks.
-
0
Here you go:
public virtual IQueryable<Shelter> Shelters { get { return _repository.GetAll(); } }