开发者

How to use rowlock and readpast with NHibernate?

开发者 https://www.devze.com 2023-02-03 10:37 出处:网络
I have an application which currently reads data from a table using the following stored procedure: CREATE PROCEDURE [dbo].[GetBatchOfEmails]

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], [MessageBod开发者_运维百科yText], [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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号