locked
Design problem for a "partner" structure RRS feed

  • Question

  • Hello everybody!

    I have a problem with the entity framework for the following structure. 

    The basic idea is to solve the problem of various types of partners related to a buissines structure (ex. an hotel). Partners could be phisical persons (Bill Gates) oder legal persons (Microsoft Inc.). 

    The following structure is what we want ideally - making use of interfaces:

    public class Partner { public int Id { get; set; } public IJuridicalUnit ReferenceJuridicalUnit { get; set; } } public interface IJuridicalUnit { int Id { get; set; } string Name { get; } } public class Person : IJuridicalUnit { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Name => string.Format("{0} {1}", FirstName, LastName); } public class Company : IOrganisationalUnit, IJuridicalUnit { public int Id { get; set; } public string CompanyName { get; set; } public JuridicalForm JuridicalForm { get; set; }

            public string LDAP_Referecence { get; set; } public string Name => CompanyName; } public class JuridicalForm { public int Id { get; set; } public string Name { get; set; } } public class Role : IOrganisationalUnit { public int Id { get; set; } public string LDAP_Referecence { get; set; } }

    It seems to me that there is no straight forward solution to integrate this into ef6. Right ?

    What are your suggestions ?

    Thanks a lot for any idea !

    Best regards, 

    Fabianus

    Thursday, March 3, 2016 2:13 PM

Answers

  • EF knows nothing about interfaces.  They exist only in your .NET code and have no representation in the database, except that any properties required by the interface will appear on your entities.

    EF does support inheritance.  You'll probably need to use that here as you will need to support an entity that has a collection of Person or Company entities.

    David


    David http://blogs.msdn.com/b/dbrowne/


    Thursday, March 3, 2016 2:39 PM

All replies

  • EF knows nothing about interfaces.  They exist only in your .NET code and have no representation in the database, except that any properties required by the interface will appear on your entities.

    EF does support inheritance.  You'll probably need to use that here as you will need to support an entity that has a collection of Person or Company entities.

    David


    David http://blogs.msdn.com/b/dbrowne/


    Thursday, March 3, 2016 2:39 PM
  • Hi David,

    thanks a lot for your response !

    Best regards,

    Fabianus

    Monday, March 14, 2016 6:42 AM