I have two tables Deal
and Cost
. Costs can be of a number of types, eg Planned, Unplanned. Every deal can have one an only one of each type of cost. This is easy enough to map as a many-to-one on deal, reulting in an IList of Costs. But what I want is to create a costs object that has named properties for each cost. So that for a database that looks like this:
Deal: Cost
ID Name ID DealID Type Value
--------- -------------------------------
1 Test 1 1 Planned 10
2 1 Unplanned 5
it is accessible like this
Deal.Costs.Planned = 10m;
Deal.Costs.Unplanned = 5m;
How is the best way to go about mapping this? Should I even be mapping it or should I just write the properties by hand to query the underlying collection?
The difficulty as i see it is mapping the properties of cost so that they map to different rows in teh same table. Using one of the columns as a discriminator.