Sample Transaction

2 posts, 0 answers
  1. Neagoe
    Neagoe avatar
    2 posts
    Member since:
    Jul 2010

    Posted 21 Mar 2011 Link to this post

    We did not find any demo application "WinForms" to find your site to run as a transaction:
    Simple matter:

     // Create a new category
    Category newCategory = new Category()
           CategoryName =
           Description =
       dbContext.Add( newCategory );
    // Update an existing category

    If you want to edit or delete category just added to the transaction is not closed but we have no reference ?
    is updated on a category below CategoryID = 1 but in this context the value of this property is not generated upon where you reference?
    Same question and delete ...

    Category updateCategory = dbContext.Categories.Where( c => c.CategoryID == 1 ).First();
       updateCategory.Description =

    // Delete an existing category

    Category categoryToDelete = dbContext.Categories.Where( c => c.CategoryID == 2 ).First();
       dbContext.Delete( categoryToDelete );

    // Save Changes
  2. Petko_I
    Petko_I avatar
    184 posts

    Posted 24 Mar 2011 Link to this post

    Hello Neagoe,

    As far as we understand you would like to obtain access to a database calculated value for a field before the transaction has been committed. In your scenario the CategoryID value is calculated by the database server. It is recommended to use the reference for the Category to update it before it is committed as the backend calculated value cannot be retrieved without a call to the database. ORM tools do not afford to predict values generated by the database servers as the rules for the calculated values for the columns can vary greatly from one database application to another. We would therefore suggest you either commit the addition of the category so that you can later update the entity without guessing what the id might be or keep the reference to the added category in a local variable.
    There is a scope operation which you can invoke to retrieve a not committed value but we would strongly advise you to use it sparingly as there are performance considerations you will need to take into account. You can flush the active transaction from the context by using our scope API. To expose the internal scope used by the OpenAccessContext you can create a separate file in which you continue the definition of the OpenAccessContext derived type in the following manner:
    public partial class EntitiesModel : OpenAccessContext
            public void Flush()
                IObjectScope scope = this.GetScope();
                if (scope == null)
                if (scope.Transaction.IsActive)
    We would like to point out again that this approach is not recommended and in your scenario we would try to keep the reference to the added category.

    Should you have further questions, do not hesitate to contact us.

    Best wishes,
    the Telerik team
  3. DevCraft banner
Back to Top