开发者

Microsoft Sync Framework 2.0 : is it possible to update the column value within the same sync transaction (Client Upload Server Update) scenario?

Let say, I have a table with 2 columns (OrderId and OrderDate). In the original design, OrderId is the surrogate (which is still somewhat meaningful to the end user since they still like to refer to OrderNumber 12345) PK with IDENTITY integer. Since we start to adopt SyncFx and to support offline client creation scenario, we decided to add a new column unique identifier (GUID) as the new PK.

in my old working V1.0 implementation, the OrderId will be assigned as negative value (-1, -2 and so on) for the offline created records. when the sync happens, the OrderId will be reassigned with the 'next' number ( the server will perform the max() + 1 on the OrderId column in the table). the logic is implemented as a Stored procedure and it will be called during the insert trigger.

Update INSERTED set OrderId = b.NextNumber
FROM INSERTED a,
(
    SELECT SyncGUID, ROW_NUMBER() OVER (ORDER BY SyncGUID) + (SEL开发者_如何学CECT MAX(OrderId) MaxID FROM Order) as NextNumber
    --select * 
    FROm Order 
    where OrderId <= 0
) b
where a.SyncGUID = b.SyncGUID

However, in V2.0, after the syc, the record is created in the server side and the OrderId did being updated (from -1 to 'next' number); however, that update change didn’t get download to the client. I was wondering

  1. I looking into the logic in the _selectchanges() SProc. i seems like i might need to manually manipulate the [local_update_peer_timestamp] in order for the enumeration to pick it up ?!
  2. Since the whole logic is running within the insert trigger (which the record is still not committed to the actual table), I am also wondering is it possible to have the enumeration being called again after the record is committed to the server table. (without calling another sync)
  3. Will the "INSTEAD OF INSERT" trigger offer any helps in this case?! I tried a few time but no workies with my limited knowledge.


Your change is not getting downloaded since it is being done inside the Sync's trigger, so the sync metadata is not getting updating to show that a change happened.

I would suggest trying to implement your code inside of your own insert trigger instead of doing the work inside of the triggers created by Sync.

Also, you will not want to use an INSTEAD OF trigger since that would replace the work Sync Framework needs to do for its change tracking.

By creating your own trigger this way, your trigger will insert the change, and on the next sync of that table, that change will get picked up.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜