Query in transaction

2 posts, 0 answers
  1. Visoot
    Visoot avatar
    6 posts
    Member since:
    Jan 2009

    Posted 26 May 2010 Link to this post

    How can I query data from database including dirtyobjects in transaction?

    I have table UsersInRoles that have column (UsersInRoleId PK bigint, UserId FK bigint, RoleId FK bigint)

    I have function to insert multiple records within 1 transaction for example...

    Begin Transaction
    INSERT INTO UsersInRoles(UsersInRoleId, UserId, RoleId) VALUES (1,1,1)
    INSERT INTO UsersInRoles(UsersInRoleId, UserId, RoleId) VALUES (2,1,2)
    INSERT INTO UsersInRoles(UsersInRoleId, UserId, RoleId) VALUES (3,1,3)
    Commit Transaction

    This function works fine with correct data but there is problem for a case below...

    Begin Transaction
    INSERT INTO UsersInRoles(UsersInRoleId, UserId, RoleId) VALUES (1,1,1)
    INSERT INTO UsersInRoles(UsersInRoleId, UserId, RoleId) VALUES (2,1,1)
    Commit Transaction

    The first record is inserted correctly but second record should not be inserted because UserId and RoleId is duplicated with the first record so I have created validation method to check data before saving in each record however the problem is I can query data from database only but it is not included dirty objects in transaction. How can I query in 1 time that include data from database and dirty objects in transaction? Could you please provide me an example or how to deal with this issue? I am not sure I need to set isolation level to READ_UNCOMMITTED or not? Thank you in advanced.
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 27 May 2010 Link to this post

    Hi Visoot,

     You should not set the isolation level to READ_UNCOMMITED as this is a setting for the concurrency control in the database, at the time of update or insert. Correct me if I am wrong but what you are trying to do is query both the database and the newly populated objects in a single query. 

    If that is the case I am afraid it is not possible, you can however use the scope.Transaction.Objects to retrieve the entities based on type and state. For example scope.Transaction.Objects<Customer>(ObjectState.New) will return a list of all the newly created(and added to the scope) entities of type Customer. Then you can append this list to the objects you have gathered from the database. 

    If this is not your case please contact us back. Hope this helps.

    Have a great day,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top