Entity Framework locking a table with a select

entity-framework table-locking transactionscope

Question

I have to take action similar to this.

select * from myTable with (xlock,holdlock)

Entity Framework is used. Can this be done? I've started aTransactionScope using theSerializable despite my selections not locking the tables, the isolation level. They should lock while I finish the transaction scope, please.

1
8
10/28/2013 7:09:13 AM

Popular Answer

It is feasible, however you must send the SQL As far as I'm aware, utilizing LINQ prevents you from adding the locking hint:

ObjectContext.ExecuteStoreCommand(
                string.Format("select 1 from [{0}] with (tablockx, holdlock) where 0 = 1",
                              tableName));

You will keep the lock until the transaction is finished if you perform it inside a transaction scope.

Here is a little additional information:

http://peplowdown.wordpress.com/2010/07/18/locking-across-servers-table-locks-with-entity-framework/

6
7/18/2010 9:35:25 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow