Reputation: 355
I have a car entity type with manufacturer and model attributes. I'd like to constraint the manufacturer attribute values. Also, when a particular manufacturer attribute value is chosen, the model attribute values available should be relevant to that particular manufacturer.
I considered implementing a manufacturer entity type and a separate sub-entity type for each manufacturer. Each sub-entity type would in turn draw model values from a look-up entity type as per diagram below.
However, each manufacturer has the same set of attributes and implementing sub-entity types doesn't seem to be right. Furthermore, as I add a new sub-entity type each time I want to represent a manufacturer the schema will grow to a big number of tables.
What is the best approach to implement those constraints?
Thank you
Upvotes: 0
Views: 142
Reputation: 14418
Your problem is that you are not representing the relationship between a car and it's model directly. Don't relate a car to its manufacturer directly, relate via the model.
Implement your data model this way:
In your Entity Framework model you can now easily see the make and model of any car. In assigning the model to a new car object, you can drill down from a selected make to the available models.
If this is a robust application with historical data, you'd probably have to include year
in the mix, such that models only exist for certain years.
Upvotes: 2