MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Design Question #257

Open GreggThelen opened 7 years ago

GreggThelen commented 7 years ago

I've a Billing Advice object. Each Billing Advice object has a child collection of Line Items. Each Line Item may be for a negative amount or a positive amount.

When the Billing Advice is DataPortal_Insert(), and only when the Billing Advice is DataPortal_Insert(), I want the Billing Advice to split itself into two Billing Advice where one has all of the positive Line Items and the other has all of the negative Line Items. Upon Insert the Billing Advice is removed from the UI so there is no concern about Updating at this point.

Otherwise for the purpose of DataPortal_Fetch() and DataPortal_Update() all of the Billing Advice objects would act the same.

At the time of DataPortal_Insert() it is rather easy to insert the same object twice, each time with a different unique Id; however, I need a way to corral the positive and negative Line Items so that they're saved in the database with the correct parent Id - positive ones attached to one Billing Advice and negative ones to the other Billing Advice.

Thoughts?

hurcane commented 7 years ago

Billing Advice is your aggregate root. Your line items should be child items, with the root object responsible for telling the lines to save. The lines won't have any DataPortal methods.

I would expect the line items to possibly have a method signature like this: Insert(int ParentID)

Within the parent, you keep track of the positive ID and the negative ID during the insert. You pass the appropriate ID into the lines's Insert method.

GreggThelen commented 7 years ago

That probably blows up transactional scope though...

hurcane commented 7 years ago

What scope do you want? The technique I suggested works great when you want to have everything saved using a single transaction. The root DataPortal method starts the transaction. The transaction does not complete until the root method is complete, which includes calls to Insert on each line.

In my project, we save bills of material that contain literally 10000 components in a single transaction using this technique.

GreggThelen commented 7 years ago

That is how I want it to work. Thanks - I'm finding this pretty easy to do.

Chicagoan2016 commented 7 years ago

@hurcane are you using [Transactional(TransactionalTypes.TransactionScope)] in dataportal insert, update methods? Thanks

hurcane commented 7 years ago

@Chicagoan2016 Yes, we use TransactionScope on any DataPortal methods that need a single transaction across the calls. We even include it on Fetch calls where the data is coming from multiple sources and we want to ensure we are getting consistent point-in-time data.