entity has many collections of other entities EF 4.2

I need to model a large number of tables in my domain... I am trying to figure out how to correctly normalize the following:

I have Address Entity which is Abstract

StreetAddress and POBoxAddress are derived from Address

Many other entities in this domain will need a collection of addresses for instance:

Vendor.Addresses
CondoComplex.Addresses
Employee.Addresses
PositionShift.Addresses
Location.Addresses
Guest.Addresses
Property.Addresses
Owner.Addresses

etc... many other enities... So I am confused on how to store these associations in EF ? As a many to many tph with a discriminator column or am I just missing the forest for the trees and there is an less complex solution ?

Answers


Inheritance is overused in entity mappings (indeed, it's overused in general, but especially in the case of mapped objects, which aren't really strongly OO in the first place and shouldn't generally have behaviors). Most of the time, you should avoid it, as it makes queries and data structures far more complicated. Do you really need two different types for StreetAddress and POBoxAddress? Why? The Post Office won't care.

There needs to be a clear, compelling case for inheritance before you take that complexity into your model. In this case, you not only don't have it, but your question indicates that you have a strong case for not using inheritance here at all.


Leaving the case of complexity of your Address entity aside, if related entities are not going to share Addresses I don't think there's a point in creating many to many relationship. I'm not sure how your abstract Address class looks like, but I would go simply with

public List<Address> Addresses {get;set;}

in your entities


Need Your Help

MySQL error with Hibernate

java mysql hibernate

I have an entity class named "NewsArticle" that has about 20 instance variables, when I use session.save() to insert the entity object into mysql, I got the following error. I have searched the int...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.