如何在 NHibernate 中使用 rowlock 和 readpast?

发布于 2024-10-11 10:20:33 字数 737 浏览 5 评论 0原文

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

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

I have an application which currently reads data from a table using the following stored procedure:

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

As you can see, the stored procedure uses ROWLOCK and READPAST so that a number of rows (controlled by @BatchSize) are read safely by one connection only. After reading, the rows are deleted.

Can anyone point me towards how I might accomplish the same with NHibernate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文