0

I have user Model, like this:

    public class User : IdentityUser<Guid>
    {
        public string FullName { get; set; }
       //... more lines
    }

Now I need to use some methods for user, that are made for base entity, so I want to add Base Entity, but it does not work.

    public class User : IdentityUser<Guid>, BaseEntity
    {
        public string FullName { get; set; }
       //... more lines
    }

I tried creating new user with only BaseEntity and then it works, but then I lose all the methods for IdentityUser which I don't want.

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
kr_v
  • 139
  • 12

1 Answers1

1

Since multiple inheritance is not possible in C#, you could have an IdentityUser as a field and wrap the properties and methods you want (assuming IdentityUser is not your own class):

public class User : BaseEntity
{
    private readonly IdentityUser<Guid> _identityUser;
    public string FullName { get; set; }

    public string UserName
    {
        get { return _identityUser.UserName; }
        set { _identityUser.UserName = value; }
    }

    public string Id
    {
        get { return _identityUser.Id; }
        set { _identityUser.Id = value ; } 
    }

    // ... etc.

    public User(IdentityUser<Guid> identityUser)
    {
        _identityUser = identityUser;
    }
}
Parrish Husband
  • 3,148
  • 18
  • 40