RollBack Transactions - [Transactional(TransactionalTypes.TransactionScope)]

RollBack Transactions - [Transactional(TransactionalTypes.TransactionScope)]

Old forum URL: forums.lhotka.net/forums/t/4759.aspx


Inquistive_Mind posted on Monday, April 28, 2008

Hello All,

                 I am trying to save two Business Objects in a single transaction.I noticed that the first business object saves and writes to the database while there is a stored procedure name error(intentional. was curious to see whether both BO would be rolled back or not) in the second business object and it throws an exception.However since the dataportal has been wrapped in the TransactionScope should'nt the database write by the first business object be rolled back? I have looked at the examples using command object etc that have been posted in this forum.I am a little confused with this approach and I am wondering whats the point in using TransactionScope if it cannot be used to Save multiple business objects as a single transaction. I am thinking of putting the code of saving the two BO's in a separate Try-Catch. I guess I am missing quite a lot here.

[Transactional(TransactionalTypes.TransactionScope)]

protected override void DataPortal_Insert()

{

int rowsinserted = 0;

using (DbConnection cn = Database.DBConnection)

{

cn.Open();

using (DbCommand cm = cn.CreateCommand())

{

UserGroupPermissions _userGroupPermissions = UserGroupPermissions.NewUserGroupPermissions(_groupId);

_userGroupPermissions.Save();

UserGroupFieldPermissions _userGroupFieldPermissions = UserGroupFieldPermissions.NewUserGroupFieldPermissions(groupID, 110 /* AssetIdentificationEdit */);

_userGroupFieldPermissions.Save();

 

}

}

}

Thanks in advance,

Vikas

sergeyb replied on Monday, April 28, 2008

What code do you have in .Save() calls to your permission objects?  Are those standard Save methods of a business object or did you override them for a specific purpose?  I was kind of expecting to see calls to some internal method, not Save calls.  Save calls invoke DataPortal again.  I wonder if this is why you are seeing this behavior…  And yes, Transactional attribute should rollback the first save.  Just out of curiosity, create internal methods and call them directly to save the data just to see if transactional support starts working again.

 

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Inquistive_Mind [mailto:cslanet@lhotka.net]
Sent: Monday, April 28, 2008 9:50 AM
To: Sergey Barskiy
Subject: [CSLA .NET] RollBack Transactions - [Transactional(TransactionalTypes.TransactionScope)]

 

Hello All,

                 I am trying to save two Business Objects in a single transaction.I noticed that the first business object saves and writes to the database while there is a stored procedure name error(intentional. was curious to see whether both BO would be rolled back or not) in the second business object and it throws an exception.However since the dataportal has been wrapped in the TransactionScope should'nt the database write by the first business object be rolled back? I have looked at the examples using command object etc that have been posted in this forum.I am a little confused with this approach and I am wondering whats the point in using TransactionScope if it cannot be used to Save multiple business objects as a single transaction. I am thinking of putting the code of saving the two BO's in a separate Try-Catch. I guess I am missing quite a lot here.

[Transactional(TransactionalTypes.TransactionScope)]

protected override void DataPortal_Insert()

{

int rowsinserted = 0;

using (DbConnection cn = Database.DBConnection)

{

cn.Open();

using (DbCommand cm = cn.CreateCommand())

{

UserGroupPermissions _userGroupPermissions = UserGroupPermissions.NewUserGroupPermissions(_groupId);

_userGroupPermissions.Save();

UserGroupFieldPermissions _userGroupFieldPermissions = UserGroupFieldPermissions.NewUserGroupFieldPermissions(groupID, 110 /* AssetIdentificationEdit */);

_userGroupFieldPermissions.Save();

 

}

}

}

Thanks in advance,

Vikas



Inquistive_Mind replied on Monday, April 28, 2008

Thanks Sergey for your response.

I think I got what I need.I need to be calling the UserGroupFieldPermissons in the Save(DataPortal_Insert) of UserGroupPermissions rather than call both the Save in the Root object(UserGroup)

Maybe I was not clear in what I am trying to achieve here.I am creating a Group and once a group is created,I am using the groupID to create the group permissions set for the group with default value false and for each permission I am creating a field permission set that will allow permissions upto the field level. The Group Permission Set is divided into different domains and I have Internal Sealed Classes for each domain.Same for Group Field Permission Set.

The hierarchy is something like this.

Group --> Group Permissions For each domain ---> Group Field Permissions For each Permission

Let me give an example.

I have group Technicians who can View,Edit,Delete an Equipment Record and in that Group of Technicians I can allow/deny some of the Technicians to edit some fields of the Equipment Record.

Thanks again for your response.I will try your suggestion.

 Vikas

Copyright (c) Marimer LLC