0

I have a Person entity class which is inherit from my BaseEntity. The project structure is on that base entity class so i cannot change or remove it.

I want to implement another base class IdentityUser coming from Microsoft.AspNetCore.Identity

But this is getting error: Class 'Person' cannot have multiple base classes: 'BaseEntity' and 'IdentityUser'

Is there any way to solve this ?

public class Person : BaseEntity, IdentityUser
{
    public int GroupId { get; set; }
    public string CardNumber { get; set; }
    public int PrivilegeId { get; set; }
    public string Name { get; set; }
    public string MiddleName { get; set; }
    public string Surname { get; set; }
    public string Password { get; set; }
    ........
    ........
    ........
}
TheMuyu
  • 579
  • 2
  • 12
  • 31

1 Answers1

3

C# is not like C++. It is not possible to inherit form more than on base class. Maybe you should convert IdentityUser to an interface.

public interface IIdentityUser
{
  int GroupId { get; set; }
  int PrivilegeId { get; set; }
  // ...
}

public class Person : BaseEntity, IIdentityUser
{
  public int GroupId { get; set; }
  public string CardNumber { get; set; }
  public int PrivilegeId { get; set; }
  // ...
}

In multiple inheritance systems the diamond problem can occurr (see Wikipedia). Also there is a discussion here.

sunriax
  • 592
  • 4
  • 16