Base solution for your next web application
Open Closed

UserRole and Role names #2415


User avatar
0
gpcaretti created

Dear All, I had the same issue shown here: UserRole topic and solved in a similar way with the payload of writing complex code.

My question is: Why don't you add a reference to Roles in UserRole class?

I post here your original code for UserRole with my little suggestion:

public class UserRole : CreationAuditedEntity<long>, IMayHaveTenant
{
        public virtual int? TenantId { get; set; }
        public virtual long UserId { get; set; }
        public virtual int RoleId { get; set; }

       // my suggestion
        [ForeignKey("RoleId")]
        public virtual Role Role { get; set; }

       public UserRole()
        {
        }

        public UserRole(int? tenantId, long userId, int roleId)
        {
            TenantId = tenantId;
            UserId = userId;
            RoleId = roleId;
        }     
}

1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Here is why we didn't do it <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/issues/221">https://github.com/aspnetboilerplate/mo ... issues/221</a>.