在实体框架中使用选择锁定表
我需要
select * from myTable with (xlock,holdlock)
使用实体框架做这样的事情。这可能吗?我已经打开了具有 Serialized
隔离级别的 TransactionScope
,但我的选择并未锁定表。我希望它们锁定,直到我完成事务范围。
I need to do something like this
select * from myTable with (xlock,holdlock)
using Entity Framework. Is this possible? I've opened a TransactionScope
with the Serializable
isolation level but my selects are not locking the tables. I'd like them to lock until I complete the transaction scope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的,但您必须发出 SQL,在使用 LINQ 时您无法添加锁定提示(据我所知):
如果您在事务范围内执行此操作,那么您将保持锁定直到完成事务。
可以在这里找到更多信息:
http://peplowdown.wordpress.com/2010/07/18/locking-across-servers-table-locks-with-entity-framework/
It is possible but you have to issue the SQL you can't add the locking hint when using LINQ (as far as I know):
If you do that in a transaction scope then you'll hold the lock until you complete the transaction.
A bit more information can be found here:
http://peplowdown.wordpress.com/2010/07/18/locking-across-servers-table-locks-with-entity-framework/