Reputation: 1433
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 ?
Upvotes: 4
Views: 296
Reputation: 117485
You can use advice from that article and process queue on server side. Then your code could look like
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
to dequeue you have just execute procedure.
Hope that helps.
Upvotes: 1