Being a newbie to CSLA.Net, I have run into a problem regarding the interaction between two editable root objects.
What I want to do is as follows:
Object 1 is relates to Inventory (and is uses the DB table 'Inventory')
Object 2 is used for writing a an inventory movement log (using 'InventoryLog' table)
\When a change is made to the Inventory object (a Sale or Goods Receive), I would like to
write an entry into the InventoryLog table. Obviously these two actions need to be wrapped in a transaction if one fails. I could do this via a stored proc, but I would like to keep the InventoryLog as an object as it has other uses elsewhere.
Could someone suggest a way in which I could get these two objects to participate in the same transacion?
Thanks
Bonio
Hello Bonio,
Take my suggestion with a grain of salt. I'm pretty new to CSLA too, hoping I'm not off base.
I think what you want to do is have Object2 be an editable child object instead of a editable root object. That way your editable root (Object1) can contain an instance of Object2 and when you save Object1, you save your child too.
You may have another class that uses the same table as Object2 that's an editable root, but that would be a different class altogether.
Someone please correct me if I'm wrong.
Regards,
Mike
That would be one way of doing it. Watch that you don't repeat the any busines logic between the two classes
Bonio,
One way of doing this is just adding this Logging feature to the Update/Insert Stored Procedure. As I understand it, your Inventory Log is just that, a log, wich I suppose won't change once written to the database. This way it is in the same transaction.
Another way to do this is to create an EditableChild (or Switchable if you also need it as an EditableRoot) and have Object1 create an instance this EditableChild upon Insert/Update and save it in DataPortal_Update/Insert within the same transaction.
Jurjen.
You should make sure your objects are designed following the use case. It is rare to have a use case which requires two editable root objects.
But if you convince yourself that this is, in fact, the case, read on...
Your use case, as described, has the requirement of saving multiple objects as a single unit (which again implies a single editable root ), and you can do this with multiple root objects through the use of a Command object.
Having read the responses to my original question, I now realise that my original design was flawed and in fact the Logging role is only a net effect of actions by the Inventory object.
What I will do is to just build logging into the Inventory object rather than have its own separate object.
Many thanks for all the help/advice received.
Bonio
Copyright (c) Marimer LLC