Hello I want to create different types of users. They will have different types of profiles and functionality. For example a Landlord and a Renter user. What would be the best way to do this? Obviously I could create different Roles for them which I will do as well but a Landlord will have different classes associated with them such as a Listing and Rental properties.
Any suggestions would be greatly appreciated.
7 Answer(s)
-
0
I can suggest to extend User class (create a few classes inherited from User), use Table-Per-Hierarchy approach which is supported by Entity Framework.
-
0
Thank you, I haven't heard of Table-Per-Hierarchy approach. Do you know of any good articles that explain it?
-
0
I can not say a specific one but you can find good articles when you search "TPH Entity Framework".
-
0
Thank you
-
0
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?
-
0
Hi,
Your repository should be defined like this I think,
private readonly IRepository<Renter, long> _renterRepository;
-
0
Oh yes you are correct. Thank you