Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
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 '12 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. –  Emmad Kareem Aug 11 '12 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 '12 at 22:34
    
@pdr Thanks for cleaning stuff up for me. The articles made for good reading guys so thanks, it's really appreciated. –  gerry doherty Aug 12 '12 at 8:28
add comment

1 Answer 1

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.

share|improve this answer
    
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. –  gerry doherty Aug 12 '12 at 8:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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