DEV Community

Cover image for Synchronize Databases with Only Five Lines of Code
Jeremy Likness ⚡️ for .NET

Posted on

Synchronize Databases with Only Five Lines of Code

DotMim.sync is a framework for synchronizing relational databases. It is a .NET Standard 2.0 library, which means it will run on multiple platforms including Windows, Linux, iOS and Android (via Xamarin) and more. It is production-ready and has been evolving for nearly a decade. The following code sample shows how easy it is to get started. This will automatically sync a client, including creating the tables and populating the data if the database doesn't already exist.

// Sql Server provider, the "server" or "hub".
SqlSyncProvider serverProvider = new SqlSyncProvider(
    @"Data Source=.;Initial Catalog=AdventureWorks;" +
    "Integrated Security=true;");

// Sqlite Client provider acting as the "client"
SqliteSyncProvider clientProvider = new

// Tables involved in the sync process:
var tables = new string[] {
    "ProductCategory", "ProductDescription", 
    "ProductModel", "Product", 
    "Address", "Customer", "CustomerAddress", 
    "SalesOrderHeader", "SalesOrderDetail" };

// Sync agent
SyncAgent agent = new SyncAgent(
    clientProvider, serverProvider, tables);

    var result = await agent.SynchronizeAsync();

} while (Console.ReadKey().Key != ConsoleKey.Escape);

In this episode of the EF Core Community Standup, the team talks with creator Sébastien Pertus who shares the project's history and demos several scenarios that illustrate how fast and easy the framework is to use.

You can find the links that were discussed in the show at:

Have feedback for the EF Core team? File an issue or join one of our many online discussions.

Top comments (3)

sipi41 profile image
Guillermo Perez

Excellent news! I haven't tried yet, as I'm in another project but looks promising... I actually purchased a program that syncs my server SQL DB to my WordPress DB, in this case, a MySQL database, fails from time to time, creates unnecessary fields (that I deleted one time by accident), I can't edit the source code also, etc...

I will give it a try, thanks for sharing! :-)

mimetis profile image
Sébastien Pertus

A quick blog post on about DMS:

Some comments may only be visible to logged-in visitors. Sign in to view all comments.