Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 使用select in实体框架锁定表_Entity Framework_Transactionscope_Table Locking - Fatal编程技术网

Entity framework 使用select in实体框架锁定表

Entity framework 使用select in实体框架锁定表,entity-framework,transactionscope,table-locking,Entity Framework,Transactionscope,Table Locking,我需要这样做 select * from myTable with (xlock,holdlock) 使用实体框架。这可能吗?我已使用可序列化隔离级别打开了一个TransactionScope,但我的选择没有锁定表。我希望它们锁定,直到我完成事务范围。这是可能的,但您必须发出SQL,在使用LINQ时无法添加锁定提示(据我所知): 如果在事务作用域中执行此操作,则将保持锁,直到完成事务 更多信息可在此处找到: ObjectContext.ExecuteStoreCommand(

我需要这样做

select * from myTable with (xlock,holdlock)

使用实体框架。这可能吗?我已使用
可序列化
隔离级别打开了一个
TransactionScope
,但我的选择没有锁定表。我希望它们锁定,直到我完成事务范围。

这是可能的,但您必须发出SQL,在使用LINQ时无法添加锁定提示(据我所知):

如果在事务作用域中执行此操作,则将保持锁,直到完成事务

更多信息可在此处找到:

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