4

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

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 完成同样的任务?

4

0 回答 0