This is a migrated thread and some comments may be shown as answers.

Transactions

1 Answer 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
webdev
Top achievements
Rank 1
webdev asked on 27 Jan 2013, 08:18 PM
Hi,

I want to use transaction with the OpenAccess ORM mapper. Unfortunately I have only found in the documentation the old api:

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
ITransaction txn = scope.Transaction;

Is this the recommended way?

If not how can I make sub-transactions. On which I can perform a rollback without the touching the surrounding transaction.
I know that I can perform a commit or rollback on the openaccess context, but what is the preferred way for a cancelling a little part of changes.

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 30 Jan 2013, 04:20 PM
Hello webdev,

Currently, the OpenAccess.ITransaction interface implemented in Telerik OpenAccess ORM does not support transaction nesting.

As an alternative, I suggest you to use a separate instance of the OpenAccessContext class for each transaction. The following snippet demonstrates this approach with the help of the Northwind database.
using (EntitiesModel dbContext = new EntitiesModel())
{
    Category newCategory = new Category();
    newCategory.CategoryName = "New Category Name";
    dbContext.Add(newCategory);
    dbContext.SaveChanges();
}
 
using (EntitiesModel dbContext = new EntitiesModel())
{
    Product newProduct = new Product();
    newProduct.ProductName = "New Product Name";
 
    //Additional property setup of the new product
 
    dbContext.Add(newProduct);
    dbContext.SaveChanges();
}


Another alternative is to try the TransactionScope class. Bear in mind that although the transaction scopes can be nested, the ambient transaction will be committed only if all the scopes (from the root scope down to the last nested scope) vote to commit it. In other words if you decide roll-back even one of the nested scopes, the whole transaction will be rolled back. A detailed article about the implementation of an implicit transaction is available here.

Perhaps you could share a little bit more information about the scenario you are trying to implement. That way we can think of some custom solution or a workaround.

I am looking forward to your feedback.

Regards,
Doroteya
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
General Discussions
Asked by
webdev
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or