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

Query in transaction

1 Answer 83 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Visoot
Top achievements
Rank 1
Visoot asked on 26 May 2010, 05:44 AM
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.

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 27 May 2010, 09:55 AM
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.
Tags
Getting Started
Asked by
Visoot
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or