{"action":"created","issue":{"url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/58","repository_url":"https://api.github.com/repos/Mimetis/Dotmim.Sync","labels_url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/58/comments","events_url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/58/events","html_url":"https://github.com/Mimetis/Dotmim.Sync/issues/58","id":330502211,"node_id":"MDU6SXNzdWUzMzA1MDIyMTE=","number":58,"title":"Subsequent changes not synced from server when batching enabled and more than one table configured","user":{"login":"gb0o","id":39327472,"node_id":"MDQ6VXNlcjM5MzI3NDcy","avatar_url":"https://avatars2.githubusercontent.com/u/39327472?v=4","gravatar_id":"","url":"https://api.github.com/users/gb0o","html_url":"https://github.com/gb0o","followers_url":"https://api.github.com/users/gb0o/followers","following_url":"https://api.github.com/users/gb0o/following{/other_user}","gists_url":"https://api.github.com/users/gb0o/gists{/gist_id}","starred_url":"https://api.github.com/users/gb0o/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gb0o/subscriptions","organizations_url":"https://api.github.com/users/gb0o/orgs","repos_url":"https://api.github.com/users/gb0o/repos","events_url":"https://api.github.com/users/gb0o/events{/privacy}","received_events_url":"https://api.github.com/users/gb0o/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-08T02:55:39Z","updated_at":"2018-06-15T20:05:32Z","closed_at":null,"author_association":"NONE","body":"I found an issue related to batching. Changes on the server are not synced to the client when `DownloadBatchSizeInKB` is non-zero . This occurs only after the initial sync to create a client db and only for more than one table. I am using an MSSQL on the server and Sqlite on the client. Steps to reproduce are:\r\n\r\n* Setup the client console app\r\nDotmim.Sync\\Samples\\Dotmim.Sync.SampleConsole\\Program.cs\r\n```c#\r\n/// <summary>\r\n/// Test a client syncing through a web api\r\n/// </summary>\r\nprivate static async Task TestSyncThroughWebApi()\r\n{\r\n    // Sqlite Client provider for a Sql Server <=> Sqlite sync\r\n    var clientProvider = new SqliteSyncProvider(\"c:/work/test.db\");\r\n    var proxyClientProvider = new WebProxyClientProvider(new Uri(\"http://localhost:54348/api/values\"));\r\n\r\n    var agent = new SyncAgent(clientProvider, proxyClientProvider);\r\n\r\n    agent.SyncProgress += (s, a) => Console.WriteLine($\"[Client] : {a.Message} {a.PropertiesMessage}\");\r\n    proxyClientProvider.SyncProgress += (s, a) => Console.WriteLine($\"[Server] : {a.Message} {a.PropertiesMessage}\");\r\n\r\n    Console.WriteLine(\"Press a key to start (be sure web api is running...)\");\r\n    Console.ReadKey();\r\n    do\r\n    {\r\n        Console.Clear();\r\n        Console.WriteLine(\"Web sync start\");\r\n        try\r\n        {\r\n            var s = await agent.SynchronizeAsync(SyncType.Normal);\r\n            Console.WriteLine(s);\r\n        }\r\n        catch (Exception e)\r\n        {\r\n            Console.WriteLine(e.Message);\r\n        }\r\n\r\n        Console.WriteLine(\"Sync Ended. Press a key to start again, or Escape to end\");\r\n    } while (Console.ReadKey().Key != ConsoleKey.Escape);\r\n\r\n    Console.WriteLine(\"End\");\r\n}\r\n```\r\n* Setup the web server\r\nDotmim.Sync\\Samples\\Dotmim.Sync.SampleUWP\\UWPSyncSample\\UWPSyncSampleWebServer\\Startup.cs\r\n\r\n```c#\r\n// Add services to the container.\r\npublic void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddMvc();\r\n\r\n    var connectionString = @\"Data Source=DESKTOP-BSIVU73;Initial Catalog=AdventureWorks;Integrated Security=true;\";\r\n    services.AddSyncServer<SqlSyncProvider>(connectionString, configuration =>\r\n    {\r\n        configuration.Add(new String [] { \"Customer\",  \"Product\" });\r\n        configuration.DownloadBatchSizeInKB = 1000;\r\n    });\r\n}\r\n```\r\n\r\n* Run the console app and web service. Confirm all desired tables are synced.\r\n\r\n```\r\n[Client] : Begin session\r\n[Client] : Loading scope ScopeId: 00ca9fe3-decf-4563-92a9-25c149505bac\r\n[Client] : Applying configuration\r\n[Client] : Configuration applied\r\n[Client] : Applying database schemas\r\n[Client] : Applying schema table TableName: Customer\r\n[Client] : Table schema applied TableName: Customer\r\n[Client] : Applying schema table TableName: Product\r\n[Client] : Table schema applied TableName: Product\r\n[Client] : Database schemas applied\r\n[Client] : Selecting changes TableName: Customer\r\n[Client] : Changes selected TableName: Customer Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Selecting changes TableName: Product\r\n[Client] : Changes selected TableName: Product Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Applying changes TableName: Customer State: Added\r\n[Client] : Changes applied TableName: Customer State: Added Applied: 901 Failed: 0\r\n[Client] : Applying changes TableName: Product State: Added\r\n[Client] : Changes applied TableName: Product State: Added Applied: 295 Failed: 0\r\n[Client] : Scope saved ScopeId: 00ca9fe3-decf-4563-92a9-25c149505bac\r\n[Client] : End session\r\nSynchronization done.\r\n        Total changes downloaded: 1196\r\n        Total changes uploaded: 0\r\n        Total conflicts: 0\r\n        Total duration :0:0:3.475\r\nSync Ended. Press a key to start again, or Escape to end\r\n```\r\n\r\n* In SSMS add a new customer\r\n\r\n```sql\r\nUSE [AdventureWorks]\r\nGO\r\n\r\nINSERT INTO [dbo].[Customer]\r\n           ([NameStyle]\r\n           ,[Title]\r\n           ,[FirstName]\r\n           ,[MiddleName]\r\n           ,[LastName]\r\n           ,[Suffix]\r\n           ,[CompanyName]\r\n           ,[SalesPerson]\r\n           ,[EmailAddress]\r\n           ,[Phone]\r\n           ,[PasswordHash]\r\n           ,[PasswordSalt]\r\n           ,[rowguid]\r\n           ,[ModifiedDate])\r\n     VALUES\r\n           (1\r\n           ,'Mr'\r\n           ,'foo'\r\n           ,'f'\r\n           ,'bar'\r\n           ,'FAFB'\r\n           ,'foo bar ltd'\r\n           ,'foo bar sales'\r\n           ,'foo.bar@domain.com'\r\n           ,'123456789'\r\n           ,'345345345345345345'\r\n           ,'1234567890'\r\n           ,NEWID()\r\n           ,GETDATE())\r\nGO\r\n```\r\n\r\n* Resync the client but no changes are synced. There should be 1 download.\r\n```\r\n[Client] : Begin session\r\n[Client] : Loading scope ScopeId: b7017c7a-c15f-4109-aef1-28d983034f3a\r\n[Client] : Applying configuration\r\n[Client] : Configuration applied\r\n[Client] : Applying database schemas\r\n[Client] : Selecting changes TableName: Customer\r\n[Client] : Changes selected TableName: Customer Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Selecting changes TableName: Product\r\n[Client] : Changes selected TableName: Product Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Scope saved ScopeId: b7017c7a-c15f-4109-aef1-28d983034f3a\r\n[Client] : End session\r\nSynchronization done.\r\n        Total changes downloaded: 0\r\n        Total changes uploaded: 0\r\n        Total conflicts: 0\r\n        Total duration :0:0:0.198\r\nSync Ended. Press a key to start again, or Escape to end\r\n```\r\n\r\n* Shutdown the web server, disable batching: i.e `configuration.DownloadBatchSizeInKB = 0;`, restart the web server.\r\n* Add another Customer in SSMS\r\n* Resync the client and confirm change is synced. There is one download as expected.\r\n```\r\n[Client] : Begin session\r\n[Client] : Loading scope ScopeId: b7017c7a-c15f-4109-aef1-28d983034f3a\r\n[Client] : Applying configuration\r\n[Client] : Configuration applied\r\n[Client] : Applying database schemas\r\n[Client] : Selecting changes TableName: Customer\r\n[Client] : Changes selected TableName: Customer Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Selecting changes TableName: Product\r\n[Client] : Changes selected TableName: Product Deletes: 0 Inserts: 0 Updates: 0 TotalChanges: 0\r\n[Client] : Applying changes TableName: Customer State: Added\r\n[Client] : Changes applied TableName: Customer State: Added Applied: 1 Failed: 0\r\n[Client] : Scope saved ScopeId: b7017c7a-c15f-4109-aef1-28d983034f3a\r\n[Client] : End session\r\nSynchronization done.\r\n        Total changes downloaded: 1\r\n        Total changes uploaded: 0\r\n        Total conflicts: 0\r\n        Total duration :0:0:0.209\r\nSync Ended. Press a key to start again, or Escape to end\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/comments/397728283","html_url":"https://github.com/Mimetis/Dotmim.Sync/issues/58#issuecomment-397728283","issue_url":"https://api.github.com/repos/Mimetis/Dotmim.Sync/issues/58","id":397728283,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzcyODI4Mw==","user":{"login":"Mimetis","id":4592555,"node_id":"MDQ6VXNlcjQ1OTI1NTU=","avatar_url":"https://avatars3.githubusercontent.com/u/4592555?v=4","gravatar_id":"","url":"https://api.github.com/users/Mimetis","html_url":"https://github.com/Mimetis","followers_url":"https://api.github.com/users/Mimetis/followers","following_url":"https://api.github.com/users/Mimetis/following{/other_user}","gists_url":"https://api.github.com/users/Mimetis/gists{/gist_id}","starred_url":"https://api.github.com/users/Mimetis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mimetis/subscriptions","organizations_url":"https://api.github.com/users/Mimetis/orgs","repos_url":"https://api.github.com/users/Mimetis/repos","events_url":"https://api.github.com/users/Mimetis/events{/privacy}","received_events_url":"https://api.github.com/users/Mimetis/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T20:05:32Z","updated_at":"2018-06-15T20:05:32Z","author_association":"OWNER","body":"Oh Sorry, it's just AdventureWorks :D \r\nOk I have everything to run the test !"}}
{"actor":{"display_login":"Mimetis"}}