Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What is the proper Domain Model for this relationship?

What is the proper Domain Model for this relationship?

Scheduled Pinned Locked Moved C#
questiondatabasedesignsalestutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Togakangaroo
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • T Togakangaroo

      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

      K Offline
      K Offline
      Kjetil Svendsen
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • K Kjetil Svendsen

        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

        T Offline
        T Offline
        Togakangaroo
        wrote on last edited by
        #3

        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, ProductCustomer

        So, in addition to the set-up I postulated being a little awkward, it is actually currently impossible for me to map with NHibernate.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups