我有一个表,其中包含与另一个系统同步问题的Queued元素
TableName | PrimaryKey | Action
--------------------------------
Products 15 Delete
Products 21 Create
Categories 9 Update
TableName:目标SQL表的名称
PrimaryKey:对应表中目标元素的PK值
操作:要执行的操作(示例:如果create->Push创建远程系统中本地表产品的ID号为21的元素)
我需要的是一种在C#中正确处理这一问题的方法。我正在考虑使用命令模式。(ASP.Net MVC4/C#)
你对这类问题有什么指导吗?
您可以使用该文章中的建议,并在服务器端处理队列。然后你的代码可能看起来像
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
要出列,您只需要执行过程。
希望能有所帮助。