Man*_*cio 8 entity-framework transactionscope table-locking
我需要做这样的事情
select * from myTable with (xlock,holdlock)
Run Code Online (Sandbox Code Playgroud)
使用实体框架.这可能吗?我已经开了一个TransactionScope
与Serializable
隔离级别,但我的选择没有锁定表.我希望他们锁定,直到我完成交易范围.
小智 6
这是可能的,但你必须发出SQL,你不能在使用LINQ时添加锁定提示(据我所知):
ObjectContext.ExecuteStoreCommand(
string.Format("select 1 from [{0}] with (tablockx, holdlock) where 0 = 1",
tableName));
Run Code Online (Sandbox Code Playgroud)
如果您在事务范围中执行此操作,那么您将保持锁定,直到完成事务.
可以在这里找到更多信息:
http://peplowdown.wordpress.com/2010/07/18/locking-across-servers-table-locks-with-entity-framework/