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
    SqliteSyncProvider("advworks.db");

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

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

do
{
    var result = await agent.SynchronizeAsync();
    Console.WriteLine(result);

} 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:

https://www.theurlist.com/efcore-standup-2020-09-02.

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

Top comments (3)

Collapse
 
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! :-)

Collapse
 
mimetis profile image
Sébastien Pertus

A quick blog post on dev.to about DMS:
dev.to/mimetis/how-to-synchronize-...

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