0

I have this entity model:

Entity Object Model

I want to have a Customer entity, which can be either a Person or an Organization, It can't be both.

As of now I came up with a customer entity which points to both organization and person but with a nullable field (meaning Guid?), which means having a non-mandatory relationship with Person and Organization. Something like:

class Customer
{
    public Guid ID { get; set; }
    public Guid? RelatedPersonID { get; set; }
    public Guid? RelatedOrganizationID { get; set; }
    public int CustomerStatus { get; set; }
    public bool IsVIP { get; set; }
    // ... other customer related properties

    public virtual Person RelatedPerson { get; set; }
    public virtual Organization RelatedOrganization { get; set; }
}

I'm using entity framework 5, codefirst approach and I haven't created the database yet. I was wondering if there's a better model that meets this requirements.

Ashkan
  • 3,322
  • 4
  • 36
  • 47
  • do you have Organizations in your system which are not customers? may be you can also consider to make all customers as organisations with person as a contact within the organisation. this would simplify things. – ravi Jul 10 '13 at 04:26
  • @ravi: unfortunately yes, an organization might not be a customer, it may be a supplier, I have the same problem for Supplier as for Customer! – Ashkan Jul 10 '13 at 20:55
  • I don't like nullable foreign keys because you have to explain how it works to somebody for them to understand and its not self explanatory. I would personally try abstracting out the common fields between the person customer and organisation customer as an interface and implement it in both person customer and organisation customer. – ravi Jul 10 '13 at 23:25
  • @ravi So you duplicate the common fields in 2 tables ? and in code use an interface to abstract it. One of the pros of this is that we have a consistent Conceptual Design. but one the cons is when you want to change a common field or add a new common field, you should do it in 2 places. I think if you make your comment as an answer would be nice. So we can discuss it more. Thnx – Ashkan Jul 11 '13 at 13:39

0 Answers0