Ticket Hash: | 8b5459fa2316bfb1c8190fc6614e789470cd4aae | |||
Title: | When I try to use a transaction, I get an error of database locked | |||
Status: | Closed | Type: | Incident | |
Severity: | Important | Priority: | Medium | |
Subsystem: | LINQ | Resolution: | Unable_To_Reproduce | |
Last Modified: | 2013-01-09 02:09:47 | |||
Version Found In: | 1.0.82.0 | |||
User Comments: | ||||
anonymous added on 2012-12-27 12:03:49:
(text/x-fossil-plain)
I would like to use a transaction, because I would like to delete the parent and all the childrens. I don't want to use the cascade deletion, because the children has other childrens and not always I want to delete the childrens of the childrens. So for that, I want to use a transaction, to ensure that I delete all the childrens of the parent and that not other user can add a new children when the first user is deleting the parent. If I try to delete only the parent, I don't get the exception, but if I try to delete the parent and her childrens, then I get an exception that say that the database is blocked. I am using the following code: using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted })) { contextEntities myContext = new contextEntities(); myContext.Clientes.Attach(paramClient); myContexto.Entry<Clients>(paramClient).Collection(p => p.Plants).Load(); for (int iteratorPlant = myContext.Plants.Local.Count - 1; iteratorPlant >= 0; iteratorPlant-- ) { myContext.Entry<Plants>(myContext.Plants.Local.ElementAt<Plants>(iteratorPlant)).State = System.Data.EntityState.Deleted; } miContexto.SaveChanges(); scope.Complete(); return true; } Thanks. mistachkin added on 2012-12-28 03:21:16: (text/x-fossil-plain) This ticket is missing key information: 1. The example code fragment is incomplete. 2. What is the schema of the underlying database tables? 3. How are the entities defined? 4. What is the exact text of the error message and/or other unexpected behavior being seen? |