locked
Syncrhonizing an 'Order' RRS feed

  • Question

  • Hi,

    I'm not sure if Synchronization Services can help me but I hope so.

    Suppose I create a new an Order in the client side. It has header and lines. When I synchronize with the server I need two things:

    - I need to be sure the header and the lines are inserted in the same transaction.
    - I need to validate the Order. Even if it was valid in the client side, I need to be sure it's valid before inserting it in the main database.

    Can this be done with Synchronization Services?

    Thanks

     

    • Moved by Hengzhe Li Friday, April 22, 2011 5:20 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, February 15, 2007 4:39 PM

Answers

  • Hi Feelyn,

    Did you try the order: Customer, Order, CustOrder? It should work. You do not need to use SyncGroup concept here if you are fine to let all three tables be handled in the same transaction. But the table order needs follow the PK relationships. Please check if you have the corect order for both Configuration.SyncTables and SyncAdapters.

    Thanks,
    Dong

    This posting is provided AS IS with no warranties, and confers no rights.
    Friday, March 20, 2009 5:13 AM
    Moderator

All replies

  • Hi Andres,

    SyncGroup should help you meet your desired behavior. SyncGroup class is a simple grouping technique used to instruct the sync runtime to upload\download changes in multiple tables as a one unit.

    So let’s say you have two tables, Order_Header and Order_Lines. To group the changes together, you would need to define a SyncTable object for each table:

    SyncTable orderHeader = new SyncTable("order_header");
    orderHeader.SyncDirection = SyncDirection.Bidirectional;

    SyncTable orderLines = new SyncTable("order_lines");
    orderLines.SyncDirection = SyncDirection.Bidirectional;

    Then to group them together, you create a sync group and attach it to both sync table objects

                   
    SyncGroup orderGroup = new SyncGroup("order");
    orderHeader.SyncGroup = orderGroup;
    orderLines.SyncGroup = orderGroup;

    One important thing here is the order of adding the sync tables to the collection, make sure the PK table goes before the FK table. This way, inserts and updates will be done in the right order on the server.

    syncAgent.SyncTables.Add(orderHeader);
    syncAgent.SyncTables.Add(orderLines);


    Regarding the second part of your question. The server provider fires ApplyingChangesEvent prior to applying any changes. The event argument exposes the DataSet of changes which contains changes from all tables in the group. This way you can validate every order. All the changes will be applied in one transaction. Failures will cause the transaction to rollback. In summary, with sync services you are in full control of what goes into your main database.

    Thanks

    Thursday, February 15, 2007 5:56 PM
  • Thanks Rafik,

    Next question. Suppose I have an 'Orders' class, with header and lines, and I want to use that class to persist the changes to the database. I want to use the synchronization framework to know which orders changed, and the new data, but no to persist the changes to the DB.

    Is it possible?

    Thanks

    Monday, February 19, 2007 9:42 AM

  • Well, I am not sure I understand what you are trying to do. When you say use "use synchronization framework to know which orders changed", I assume you have made changes to either the client or server databases. If so, then you can always call GetChanges() on either provider to get DataSet of changes. You can use the dataset for any propose.

    I may be able to give you a better answer if I could understand your scenario better.  

    Tuesday, February 20, 2007 3:07 AM
  • I want to know what changed in the client.

    Basically, I can use built-in stuff to push the server changes in the tables to the client, as I don't want to perform validations and that level, but I want to use my own business logic when pushing the changes from the client to the server.

    I'll try the approach you suggest.

    Thanks,

    Andres

    Wednesday, February 21, 2007 6:26 PM
  • Hello Rafik,

    What you did suggestion for Master/Detail tables on Data Synchronize is correct. But in my case, if it has tables Customer, Order and one Link table CustOrder, it won't work as my required.

    Table Customer:  CustomerID, CustomerName
    Table Order:  OrderID, OrderName, Num
    LinkTable CustOrder: CustomerID, OrderID

    I put them into SyncTableCollection: Customer, Order, CustOrder and do DataSynchronize, it always got failed. Byt SQL Tracing Monitoring, it does like this way:

    For multiple insert, it will always insert Customer, CustOrder and Order.
    For multiple delete, it will always delete Order, CustOrer and then Customer.

    By above orders, it will not work properly as my want forever.

    Could u please give some idea?

    Appreciate your kind help.

    Best regards,
    Feelyn
    Monday, March 16, 2009 3:20 AM
  • Hi Feelyn,

    Are you sure that you put the tables into SyncTableCollection with the sequence as "Customer, Order, CustOrder" instead of "Customer, CustOrder, Order"? From your SQL tracing, it seems that you didn't set the table order right.

    Thanks,
    Dong
    This posting is provided AS IS with no warranties, and confers no rights.
    Wednesday, March 18, 2009 10:18 PM
    Moderator
  • Hi Dong,

    I did try the following orders: Customer, CustomerOrder, Order; Order, CustomerOrder, Customer. But none of them is working.

    even i did put them into two diff syncgroups: Customer, CustomerOrer; Order, CustomerOrer. But it's still not working.

    Appreciate you can give me best support.

    Feelyn
    Thursday, March 19, 2009 1:43 AM
  • Hi Feelyn,

    Did you try the order: Customer, Order, CustOrder? It should work. You do not need to use SyncGroup concept here if you are fine to let all three tables be handled in the same transaction. But the table order needs follow the PK relationships. Please check if you have the corect order for both Configuration.SyncTables and SyncAdapters.

    Thanks,
    Dong

    This posting is provided AS IS with no warranties, and confers no rights.
    Friday, March 20, 2009 5:13 AM
    Moderator