4

I have a table containing Queued elements for synchronization issues with another system

TableName | PrimaryKey | Action    
--------------------------------
Products       15         Delete
Products       21         Create  
Categories      9         Update

TableName : The name of the targeted SQL table

PrimaryKey : The PK value of the targeted element within the corresponding table

Action : Action to do (Example : If create -> Push the creation of the element with ID number 21 of the local table Products in the remote system)

What I need is a way to handle this properly in C#. I am thinking in using the Command Pattern. (ASP.Net MVC4/C#)

Do you have any guidance about this type of issues ?

4

1 回答 1

1

您可以使用该文章中的建议并在服务器端处理队列。然后你的代码可能看起来像

create table TQueue (TableName nvarchar(128), PrimaryKey int, Action nvarchar(128))

create procedure sp_TQueue_Pop
as
begin
    declare @TableName nvarchar(128), @PrimaryKey int, @Action nvarchar(128)
    declare @temp_pop table (TableName nvarchar(128), PrimaryKey int, Action nvarchar(128))

    begin transaction

    select @TableName = null, @PrimaryKey = null, @Action = null

    delete top (1)
    from TQueue with (rowlock, readpast)
    output deleted.* into @temp_pop

    select @TableName = TableName, @PrimaryKey = PrimaryKey, @Action = Action
    from @temp_pop

    --================================================
    --  do your processing here
    --================================================

    select @TableName, @PrimaryKey, @Action
end

要出队,您只需执行程序。

希望有帮助。

于 2013-08-04T12:44:11.517 回答