StrataFrame Forum
Back
Login
Login
Home
»
StrataFrame Application Framework - V1
»
Business Objects and Data Access (How do I?)
»
Modify/update same row more than two times from BO on transaction not...
Modify/update same row more than two times from BO on transaction not update it from 2nd time...
Post Reply
Like
1
Modify/update same row more than two times from BO on transaction not...
View
Flat Ascending
Flat Descending
Threaded
Options
Subscribe to topic
Print This Topic
RSS Feed
Goto Topics Forum
Author
Message
Fabian R Silva, -
Fabian R Silva, -
posted 12 Years Ago
ANSWER
Topic Details
Share Topic
Group: StrataFrame Users
Posts: 153,
Visits: 1.2K
Hello,
problem is that when loop the 2nd time, Save(lOnTr, sTrKEy) not do nothing because isDirty() is false... (1st time work ok)
how I can update a 2nd time the same table "Counter" on a transaction?
I need this because this will lock the number on MyTabkecounter an allow to use it in AnotherTable on a transaction without fear of that this number can be repeated
MyTableCounter
------------------------------
Id
|
Number
-----------------------------
1
5
2
99
3
999
dsk = "myDB"
lOnTr = true
sTrKey = "aTrKey"
BusinessLayer.TransactionBegin(dsk, trKey, IsolationLevel.ReadCommitted);
MyTableCounter.FillByPrimaryKey(1);
for(lnk=0;lnk<=5;lnk++)
{
MyTableCounter.Number += 1;
MyTableCounter.Save(lOnTr, sTrKey); --> this doesn't execute from 2nd time
AnotherTable.NewRow();
AnotherTable.MyTableCounterId = MyTableCounterId.Id;
AnotherTable.Number = MyTable.Number;
AnotherTable.Date = DateTime.Now.Date;
AnotherTable.Save(lOnTr, sTrKey);
}
MyTableCounter.FillByPrimaryKey(2);
for(lnk=0;lnk<=5;lnk++)
{
MyTableCounter.Number += 1;
MyTableCounter.Save(lOnTr, sTrKey); --> this doesn't execute
AnotherTable.NewRow();
AnotherTable.Number = MyTable.Number;
AnotherTable.Date = DateTime.Now.Date;
AnotherTable.Save(lOnTr, sTrKey);
}
BusinessLayer.TransactionCommit(dsk, sTrKey);
Tags
transactions
Reply
Like
1
Replies
StrataFrame Team
S
StrataFrame Team
posted 12 Years Ago
ANSWER
Post Details
Share Post
S
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
There is a way to do this, but purists would frown upon it
Since you're saving the same record over and over again instead of creating a new record, we need to tell the MyTableCounter business object that it isn't really "saved." The flag that is preventing it from saving after the first time is an internal field called _IsSavedOnTransaction. You need to use Reflection to set that field back to False each time before you try to save the MyTableCounter business object. I say purists would hate it because they say you should never tamper with something using Reflection. In this case, it works just fine.
using System.Reflection;
...
//-- Get a reference to the FieldInfo of the field we need to set
FieldInfo isSavedOnTransactionField = MyTableCounter.GetType().GetField("_IsSavedOnTransaction", BindingFlags.NonPublic | BindingFlags.Instance);
...
//-- In your loop before you save the BO
isSavedOnTransactionField.SetValue(MyTableCounter, false);
Reply
Like
2
Andrew Harper
Andrew Harper
posted 9 Years Ago
ANSWER
Post Details
Share Post
Group: StrataFrame Users
Posts: 91,
Visits: 3.4K
Hi Ben,
I am facing the same situation as described in this post.
Within a transaction I do the following
1. Save BoOrderMaster to insert a new OrderMaster record with a boOrderMaster.Status ='T'
2. Save BoOrderLines to insert the orderlines
3. Set boOrderMaster.Status ='U'
4. Save BoOrderMaster
5. commit
Step 4 is not updating the database
As per your previous suggestion I have tried the inserting following code prior to Step 4
Dim isSavedOnTransactionField As FieldInfo
isSavedOnTransactionField = boOrderMaster.GetType().GetField("_IsSavedOnTransaction", BindingFlags.NonPublic Or BindingFlags.Instance)
isSavedOnTransactionField.SetValue(boOrderMaster, False)
The
isSavedOnTransactionField.SetValue(boOrderMaster, False)
statement throws an error.
I have been able to get around the problem in this instance by performing steps 3 and 4 after the commit but am wondering if am missing something here and/or if the suggested work around using reflection is still valid and has been tested.
TIA Andy
Edited
9 Years Ago by
Andrew Harper
Reply
Like
1
GO
Merge Selected
Merge into selected topic...
Merge into merge target...
Merge into a specific topic ID...
Open Merge
Threaded View
Threaded View
Modify/update same row more than two times from BO on transaction not...
Fabian R Silva, -
-
12 Years Ago
There is a way to do this, but purists would frown upon it :) Since...
StrataFrame Team
-
12 Years Ago
Hi Ben, I am facing the same situation as described in this post....
Andrew Harper
-
9 Years Ago
thanks you for the response Today I ended up doing a process to...
Fabian R Silva, -
-
12 Years Ago
Post Reply
Like
1
Similar Topics
Post Quoted Reply
Reading This Topic
Login
Login
Remember Me
Reset Password
Resend Validation Email
Login
Explore
Messages
Mentions
Search