loading...
Cover image for Synchronize Databases with Only Five Lines of Code
.NET

Synchronize Databases with Only Five Lines of Code

jeremylikness profile image Jeremy Likness ⚡️ ・2 min read

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.

Posted on by:

jeremylikness profile

Jeremy Likness ⚡️

@jeremylikness

Hi! I am a longtime developer with a passion to empower other developers to be their best. I focus on cloud development and everything related to data access from .NET and .NET Core.

.NET

.NET is an open source developer platform, created by Microsoft, for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, gaming, and IoT.

Discussion

pic
Editor guide
 

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