Thread is closed for posting
2 posts, 0 answers
  1. webdev
    webdev avatar
    3 posts
    Member since:
    Jan 2011

    Posted 27 Jan 2013 Link to this post


    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.
  2. Doroteya
    Doroteya avatar
    498 posts

    Posted 30 Jan 2013 Link to this post

    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";
    using (EntitiesModel dbContext = new EntitiesModel())
        Product newProduct = new Product();
        newProduct.ProductName = "New Product Name";
        //Additional property setup of the new product

    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.

    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top