如何在 NHibernate 中使用 rowlock 和 readpast?
我有一个应用程序,当前使用以下存储过程从表中读取数据:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论