如何在NHibernate中使用rowlock和readpast?

时间:2011-01-11 15:22:03

标签: nhibernate optimizer-hints rowlocking

我有一个应用程序,它使用以下存储过程从表中读取数据:

CREATE PROCEDURE [dbo].[GetBatchOfEmails] 
@BatchSize  INT 
AS
BEGIN
    SET NOCOUNT ON;
    WITH ResultSet AS 
    (
        SELECT TOP(@BatchSize) [To], [Subject], [MessageBodyText], [MessageBodyHtml], 
                [From], [ReplyTo], [DateCreated], [EmailId]
        FROM SendMailQueue WITH (ROWLOCK, READPAST)
        ORDER BY TableId
    )
    DELETE FROM ResultSet
    OUTPUT deleted.[To], deleted.[Subject], deleted.MessageBodyHtml, deleted.MessageBodyText,
            deleted.ReplyTo, deleted.[From], deleted.EmailId, deleted.DateCreated 
END

如您所见,存储过程使用ROWLOCK和READPAST,因此只能通过一个连接安全地读取多个行(由@BatchSize控制)。读取后,行将被删除。

有人能指出我如何用NHibernate完成同样的工作吗?

0 个答案:

没有答案