# Region Synchronization unit Void Syncunit () {progresscontent = "Synchronization unit ..." ; VaR Query = context. getunitsquery (). Where (P => P. shopuniqueid = App . Currentshop. uniqueid); context. Load (query, loadunitcallback, Null );} Void Loadunitcallback ( Loadoperation < Rp_unit > Loadop ){ // Server data Ienumerable < Rp_unit > Serverunits = context. rp_units; // Client data Ienumerable < Rp_unit > Clientunits; // Obtain data Using ( VaR Helper = New Localdb. Unithelper () {Clientunits = helper. getlist ();} // Obtain the intersection to synchronize the existing and updated objects. VaR Intersectunits = serverunits. Intersect (clientunits, New Unitentitycompare ()); // Traverse the Intersection Set Foreach ( VaR Item In Intersectunits ){ // Obtain the data to be updated on the server and the client based on the items in the intersection. VaR Serverunittoupdate = serverunits. First (P => P. uniqueid = item. uniqueid ); VaR Clientunittoupdate = clientunits. First (P => P. uniqueid = item. uniqueid ); // Compare the update time. If the update time is the same, ignore the operation. If (Clientunittoupdate. updatedate! = Serverunittoupdate. updatedate ){ // Update the client if the server is newer If (Clientunittoupdate. updatedate <serverunittoupdate. updatedate ){ Using ( VaR Helper = New Localdb. Unithelper () {Helper. updateunit (serverunittoupdate );}} // Otherwise, update the server Else {Serverunittoupdate. updatedate = clientunittoupdate. updatedate; serverunittoupdate. namecn = clientunittoupdate. namecn; serverunittoupdate. nameen = clientunittoupdate. nameen ;}}} // Obtain the difference set between the server and the client to synchronize entities that do not exist on the server or client. VaR Effectserver = serverunits. clientt (clientunits, New Unitentitycompare ()); // Traverse the difference set. // you do not need to use foreach because you want to modify the set. For ( Int I = 0 ; I <effectserver. Count (); I ++ ){ VaR Item = effectserver. elementat (I ); // If the last local update time is before the data update time, add the data to the client If (! Clientshopinfo. lastupdatedate. hasvalue | clientshopinfo. lastupdatedate <servershopinfo. lastupdatedate ){ Using ( VaR Helper = New Localdb. Unithelper () {Helper. addunit (item );}} // Otherwise, the data has been deleted from the local database and deleted from the server database. Else {Context. rp_units.remove (item );}} // Obtain the difference set between the server and the client to synchronize entities that do not exist on the server or client. VaR Required tclient = clientunits. Capacity T (serverunits, New Unitentitycompare ()); // Traverse the difference set. // you do not need to use foreach because you want to modify the set. Foreach ( VaR Item In Required tclient ){ // If the last local update time is before the data update time, remove the data from the client If (Clientshopinfo. lastupdatedate <servershopinfo. lastupdatedate ){ Using ( VaR Helper = New Localdb. Unithelper () {Helper. deleteunit (item );}} // Otherwise, the client data is added to the server. Else {Context. rp_units.add (item) ;}} syncoperations. Remove ( "Unit" );} # Endregion