tags:

views:

25

answers:

1

I've got a scenario something like this mock class heirachy

  • Order
    • OrderLine
    • Product
  • Customer
    • OrderNotes

which creates some tables like

  • Customer
  • Product
  • CustomerOrderNotes (CustomerId, OrderId)
  • Order (CustomerId)
    • OrderLines (OrderId, ProductId)

I've got this mapped to NHibernate and everything is working fine.

So now I want to create an in edit version of this object heirachy, and persist it to the database as well.

I'm using asp.net and want to save the in edit changes to separate rows, and then only when publish is pushed to commit the changes to the live row. (I'm planning on doing the copying from the edit data to the live data)

Using the same object model is it possible to store the in edit data in separate tables?

If not I could create an EditOrder class that derives from Order, but then EditOrder would still point to OrderLine, and Customer. So any changes from OrderLine and Customer would get saved to the live rows. For NHibernate it appears I would need to create a separate heirachy

  • EditOrder
    • EditOrderLine
    • EditProduct
  • EditCustomer
    • EditCustomerNotes

without creating a generic behemoth that let you defined each class used in this heirachy I'm not sure which route to take.

I really want to use one class heirachy, rather than maintain two class heirachies.

The other option is to serialize the object heirachy for in edit onto the user class. But then if one of the class changes I'll have to wipe out the data, rather than run a database migration script.

Another solution is to use another database/session factory with different mapping files.

What is the recommended way of handling a scenario like this?

A: 

The two sets of tables are there to support two different states (published/awaiting approval (or the like)).

If possible, I recommend making this state explicit in your model, and save everything in the same table.

The client of the published objects will then somehow have to exclude the non-published objects.

Martin R-L
Yeah that's one option, but then as you say have to filter by this whenever you do a select for the published data.Also each object would have to know it's status, unless all queries link back to the parent entity that knows if it is published or just edit data. For editing this would be the case, but if I just wanted to pull out Customers or Notes I wouldn't necessarily want to join to Order.For the moment going to try binary serializing the edit data. Although this has issues of it's own.