I finally figured this out. I finally realized I needed to put the tentantId within the query. My bad.
var renterOrgUnit = await _organizationUnitRepository.FirstOrDefaultAsync(o => o.TenantId == renter.TenantId && o.DisplayName.Equals("Renter"));
I can save the user roll just fine. But the OU isn't working. This below line is bringing back an Id of 3864 but the Id of the OU should be 2. So it throws an exception when it tries to save the to the link between the OU and the user because it can't find that ID.
var renterOrgUnit = _organizationUnitRepository.FirstOrDefaultAsync(o => o.DisplayName.Equals("Renter"));
I have a Renter type of user setup through table per hierarchy design that I want to automatically assign a Role and OU I have setup. What is the easiest way to do this?
Originally I was going to do something similar to this. But I obviously do not have the renter id yet as I am creating the user.
//Assign renter role
var renterRole = await _roleManager.GetRoleByNameAsync("Renter");
if (renterRole != null)
{
renter.Roles.Add(new UserRole(AbpSession.TenantId, renter.Id, renterRole.Id));
}
//Assign to OU
var renterOrgUnit = _organizationUnitRepository.FirstOrDefaultAsync(o => o.DisplayName.Equals("Renter"));
if (renterOrgUnit != null)
{
await UserManager.AddToOrganizationUnitAsync(renter.Id, renterOrgUnit.Id);
}
Oh yes you are correct. Thank you
I created my Table per hierarchy type of user and named it Renter. Which worked just fine. It automatically created a column in the DB called Discriminator.
My issue is now when I am creating my service I am having issues querying the DB. At first I tried doing something similar to this
private readonly IRepository<Renter> _renterRepository;
But it states that Authorization.User.Renter.Renter cannot be used as type parameter TEntity. So I was going to try and use the UserManager like how you do in the UserAppService
var query = UserManager.Users
.Include(u => u.Roles)
But I am unsure how I can just grab the Renters based off of the Discriminator column that entity framework created. Do you have any ideas?
I don't fully understand your first point to not add foreign key TenantId property because then it sounds like I should for point 2 and 3. I think the reason it doesn't. make much sense is because I never understood the benefits of having the tenant data in separate databases. That is for sure over my head as Multi-tenancy is so new to me.
2 and 3 make perfect sense to me. 3 fits my scenario the best. I am going to switch to IMustHaveTenant.
The reason is as we are in Alpha testing and through Beta testing, this app is actually going to be more of a single tenant app and Multi-tenancy will be turned off. But I want to design the system to support Multi-tenancy so in the future once we have ironed out all the bugs and quirks of the system we will be opening it up to multi-tenancy. So I have to be careful how I design it.
Perfect thank you. I did figure out to create a second Edition named Professional and then I gave the Chat feature the ID for that Edition and that worked as well. That way when we are ready to incorporate the Chat feature back it will be super easy to do so.
Again thank you
I am very new to Multi-Tenant applications.
I have some Entities that I inherit from the User class. So, for example, a Renter inherits from User and a Landlord inherits from a user. Then I have some Entities that map to tables that are a one to many relationships between the Renter and also the Landlord such as LandlordDemographics. Should classes like LandlordDemographics implement the IMayHaveTenant interface and have the TenantId Foreign key in it? So basically should all classes have the Tenant Id in them when developing a Multi-Tenant application? or should only the main class such as the User class have it?
What do you mean by Seed method?
Just through the Database should work. Thank you
Will this work for Single tenant mode? I didn't realize you can login as host user for a single tenant mode.