locked
Multi Inheritance in EntityFramework RRS feed

  • Question

  • User-1112275155 posted

    Hi All,

    In a Business context i have following case :

    A user class that inherit from IdentityUser

    public class AuthUserProfile : IdentityUser
    {
    
    }

    And all domain class should inherit from base entity called : BaseEntity

    public class Foo : BaseEntity
    {
    
    }

    How to force user class inheriting from both IdentityUser and BaseEntity in an EntityFramework CodeFirst Approach ?

    Regards.

    NextApp

    Tuesday, May 23, 2017 9:37 AM

All replies

  • User-1509636757 posted

    Multiple inheritance (inherit multiple classes as parent to a derived class) is nohere here to help in C#. You require to think of some other approach.

    Tuesday, May 23, 2017 12:14 PM
  • User-271186128 posted

    Hi Sir,

    How to force user class inheriting from both IdentityUser and BaseEntity in an EntityFramework CodeFirst Approach ?

    According to your description, in C# that's not allowed to inherit multiple classes, might you could use interface to resolve this problem, see the following code:

        //define interface
        public interface IBaseEntity
        {
            DateTime CreateTime
            {
                get; set;
            }
    
            string Creator
            {
                get; set;
            }
        }
    
        //inherit from IdentityUser(class),IBaseEntity(interface)
        public class AuthUserProfile : IdentityUser, IBaseEntity
        {
            public DateTime CreateTime
            {
                get; set;
            }
    
            public string Creator
            {
                get; set;
            }
        }
    
    

    Best regards,
    Dillion

    Wednesday, May 24, 2017 5:06 AM