3

If I have a People table and those people can be at different addresses, and each address can have more than one person, thats a many-to-many relationship.

So, using ORMs like Entity Framework and Django, I've got the hang of doing that. But my problem is that there are different types of people, like employees and customers and other clients that all have these fields also.

This would leave me with a top level class called Person which has a many-to-many relationship with Address and then these other classes (Customers, etc.) that inherit from person.

I read that there are different types of inheritance, so what would be the best approach?

4
  • 5
    Hi Gerry, I've tried to tidy your question up a bit, remove the irrelevant bits and focus on what I thought was the question. Hopefully, this will stop the votes to close. If I've completely changed the question or tone in any way, feel free to revert it.
    – pdr
    Aug 11, 2012 at 16:15
  • My understanding is that if your using EF, you don't choose the type of inheritance, so I think you should not worry about the type of inheritance. What you need to worry about is if you build the model using inheritance, will you be able to use LINQ efficiently to access the data or not.
    – NoChance
    Aug 11, 2012 at 21:59
  • 1
    Ayende described in 2009 what the various NHibernate strategies are (table per hierarchy, table per concrete class, table per subclass, unioned subclasses).
    – Jeroen
    Aug 11, 2012 at 22:34
  • @pdr Thanks for cleaning stuff up for me. The articles made for good reading guys so thanks, it's really appreciated. Aug 12, 2012 at 8:28

1 Answer 1

2

Single-table inheritance is probably the easiest to understand and to maintain. That said, if you have a large number of differences between the inherited objects, you're going to end up with an equally large number of null fields all over your table. When that becomes apparent, you can (relatively easily) switch to using multi-table inheritance.

Links refer to Entity Framework.

1
  • Yeah, I agree. Single table inheritance would be OK for what I am doing at the moment as I'm not predicting a huge number of records and it's a limited amount of derived classes. Table per Hierarchy seems more intuitive to me though and I read that it worked better for situations that require large amounts of records. Good articles and thanks. Aug 12, 2012 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.