StrataFrame Forum

Conflict between interface and database logic. Need help (idea)

http://forum.strataframe.net/Topic27466.aspx

By dgsoft - 6/17/2010

Hi,

I have for example 2 tables with 1-to-1 relation.

When I add record to Master table - INSERT trigger add record to SLAVE table



Now I have a form where data from 2 tables present.

When I click "NEW" toobar button I must be able to modify data like all fields located in same table.

For this reason I have 2 BO on the form and set of textboxes with data binging.



Problem begins when I click "SAVE"



When I save MASTER table - trigger automatically creates record in SLAVE table, and when I call SAVE() for child BO - I have key duplicates.



I try to create instance of same BO and try to make MergeFrom() but data is not updated.



Need idea, how to be in this case.. what the best solution for it?



Thanks

Denis
By dgsoft - 6/17/2010

The idea with MergeDataFrom() maybe not bad in this case.. but - it does not bring changes to the database after Save() (but in debugger I can see updated CurrentDataTable with new values). Why?
By Edhy Rijo - 6/17/2010

dgsoft (06/17/2010)
The idea with MergeDataFrom() maybe not bad in this case.. but - it does not bring changes to the database after Save() (but in debugger I can see updated CurrentDataTable with new values). Why?




Hi Denis,



Probably the row state is being reset like in some cases of CopyDataFrom() and you may need to enumerate the BO and set the row state to "adding".
By dgsoft - 6/17/2010

Hi,

In my case it should not be added.. it must be 'modified'..



The problem is.. my BO on the form has one "ADDED" row.. but after MASTER table .SAVE() - the record appears in SLAVE TABLE by trigger..

When I save SLAVE BO - then I have error with duplicate records.



When I copy data to another instance of BO and try to save its not commit changes after MergeDataFrom()

even if I call Edit() and change property SetDirtyOnEdit true.



How can I change the rowstate? This property is ReadOnly



Thanks

Denis
By Edhy Rijo - 6/17/2010

I basically enumerate the BO and change the status like this:





For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()

If StockBO.CurrentRow.RowState <> Data.DataRowState.Modified Then

StockBO.CurrentRow.SetModified()

End If

Next





In the above sample bizTransactionItemsStock1 is the BO.
By Larry Caylor - 6/17/2010

Hi Dennis,

You may have a good reason for using a trigger on your master table, but if you are always adding a slave (child) object on the same form whenever you add a master (parent) object, you may be better off using the SF parent/child functionality to maintain a one-to-one relationship. This would eliminate the save issue you are currently seeing. Of course if your application allows a parent object to be added by itself on a form or by other means and you need to ensure that a default child object is also added, the trigger would be the way to go.

-Larry