Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Different types of users #1542


User avatar
0
joe704la created

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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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.

  • User Avatar
    0
    joe704la created

    Thank you, I haven't heard of Table-Per-Hierarchy approach. Do you know of any good articles that explain it?

  • User Avatar
    0
    hikalkan created
    Support Team

    I can not say a specific one but you can find good articles when you search "TPH Entity Framework".

  • User Avatar
    0
    joe704la created

    Thank you

  • User Avatar
    0
    joe704la created

    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?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Your repository should be defined like this I think,

    private readonly IRepository<Renter, long> _renterRepository;
    
  • User Avatar
    0
    joe704la created

    Oh yes you are correct. Thank you