如何使用EF4强制UPDLOCK和READPAST? [英] How to force UPDLOCK and READPAST with EF4?
问题描述
有人可以告诉我如何通过EF4强制读取将锁升级为UPDLOCK并使用READPAST提示吗?
Can someone tell me how to force a read via EF4 to escalate the lock to an UPDLOCK and also use the READPAST hint?
我基本上试图从存储过程中移动做这样的事情:
I am basically trying to move from a stored proc doing something like this:
BEGIN TRAN my_trans
BEGIN TRAN my_trans
- - 获取下一条记录
-- get next record
SET @TempKey = SELECT TOP 1 Key FROM MyTable WITH(UPDLOCK,READPAST).....
SET @TempKey = SELECT TOP 1 Key FROM MyTable WITH (UPDLOCK, READPAST) .....
- 将记录状态设置为进程中
-- status the record as inprocess
UPDATE MyTable SET Status ='InProcess'.. WHERE Key = @TempKey ....
UPDATE MyTable SET Status = 'InProcess'.. WHERE Key = @TempKey ....
- 返回我们标记的记录的ID
-- return the id of the record we marked
SELECT @TempKey
SELECT @TempKey
..提交或回滚交易......
..Commit or Rollback the transaction...
等..
它基本上将表数据视为一个队列..第一个读取记录锁定它..其他人都读取过锁定的记录,以免引起等待。
It's basically treating the table data like a queue.. first one to read the record locks it.. everyone else reads past the locked record as to not cause a wait.
我已经读过了g关于明确设置TransactionScope和IsolationLevel属性,但我找不到任何类似于我正在尝试做的事情。
I've been reading about explicity setting the TransactionScope and IsolationLevel properties, but I can't find anything quite like what I'm trying to do.
任何帮助将不胜感激 -
Any help would be appreciated-
谢谢 -
推荐答案
嗨Kenneth,
Hi Kenneth,
我们正在调查您的问题,并会尽快回复。
We're looking into your question and will respond as soon as possible.
同时,如果您还没有,请查看以下内容:
Meanwhile, take a look at the following if you haven't already:
- LINQ to Entity中的悲观并发?
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5219035b-aaa9-4917-b2f2-852b5d8449ea/
- Pessimistic concurrency in LINQ to Entity?
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/5219035b-aaa9-4917-b2f2-852b5d8449ea/
- 使用存储过程在实体框架中进行悲观锁定
http://social.msd n.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a5b1e53b-3bdb-4da5-bbfd-3490544974d9
- Pessimistic locking in Entity Framework using Stored Procedures
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a5b1e53b-3bdb-4da5-bbfd-3490544974d9
谢谢,
Cathy Miller
Cathy Miller
这篇关于如何使用EF4强制UPDLOCK和READPAST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!