What is the proper Domain Model for this relationship?
-
A Customer can have multiple Products and a Product can be assigned to zero to more Customers But, there are some items (such as BasePrice and DefaultPrefix) that are implicit to a customer-product relationship. In the database this can be modeled as Table Customer with Columns CustomerId, Name, etc. Table Product with Columns ProductId, Name, etc. Table CustomerProduct with Columns CustomerId, ProductId, BasePrice, DefaultPrefix, etc. How would you model this as Domain Objects? All I could think of is Customer ..CustomerId ..Name ..AssignedProduct[] Products Product ..ProductId ..Name ..Customer[] Customers AssignedProduct : Product ..Customer Customer ..BasePrice ..DefaultPrefix But that doesn't strike me as too slick (an Assigned Product has a Customer and a Customers[]???) and as this simplified example gets closer to what I actually have to model, this design starts to have problems among which is that NHibernate can't model some of this stuff
-
A Customer can have multiple Products and a Product can be assigned to zero to more Customers But, there are some items (such as BasePrice and DefaultPrefix) that are implicit to a customer-product relationship. In the database this can be modeled as Table Customer with Columns CustomerId, Name, etc. Table Product with Columns ProductId, Name, etc. Table CustomerProduct with Columns CustomerId, ProductId, BasePrice, DefaultPrefix, etc. How would you model this as Domain Objects? All I could think of is Customer ..CustomerId ..Name ..AssignedProduct[] Products Product ..ProductId ..Name ..Customer[] Customers AssignedProduct : Product ..Customer Customer ..BasePrice ..DefaultPrefix But that doesn't strike me as too slick (an Assigned Product has a Customer and a Customers[]???) and as this simplified example gets closer to what I actually have to model, this design starts to have problems among which is that NHibernate can't model some of this stuff
Hi. Do you really need the customer relation in the product object? If your app has a customer point of view, my suggestion would be: Customer ..CustomerId ..Name ..AssignedProduct[] Products Product ..ProductId ..Name AssignedProduct : Product ..BasePrice ..DefaultPrefix Kjetil
-
Hi. Do you really need the customer relation in the product object? If your app has a customer point of view, my suggestion would be: Customer ..CustomerId ..Name ..AssignedProduct[] Products Product ..ProductId ..Name AssignedProduct : Product ..BasePrice ..DefaultPrefix Kjetil
The short answer is no, multiple Customers can have instances of the same product (though in this case, different AssignedProduct) so it should be possible to navigate from Product to all Customers that are assigned it. Also, I've tried that set-up already and it has some more esoteric disadvantages. The long answer is that this is a simplification of slightly more complicated schema. Basically, imagine the relations between Location, Customer, Product, and Container for a company which has multiple Locations at which it rents out Containers for Customers to store Product in. A Customer can exist at multiple Locations and a Location can have multiple customers (again, the existance of a relation entails additional data); a Customer can have mutliple Products and a Product can be assigned to multiple Customers - which have to be at a location to have a product assigned. Finally, each Product that is assigned to a customer can be stored in zero or more Containers. The database in the meantime is not completely normalized, and since it is legacy, I cannot change it. It looks something like this:
Location
Customer
Product
Container
CustomerLocation with fk to Location, Customer
ProductCustomer with fk to Product, CustomerLocation
ContainerProduct with fk to Container, ProductCustomerSo, in addition to the set-up I postulated being a little awkward, it is actually currently impossible for me to map with NHibernate.