只需五行代码即可同步数据库
DotMim.sync是一个用于同步关系数据库的框架。它是一个 .NET Standard 2.0 库,这意味着它可以在包括 Windows、Linux、iOS 和 Android(通过 Xamarin)在内的多个平台上运行。它已达到生产就绪状态,并经过了近十年的发展。以下代码示例展示了它的入门有多么简单。这段代码会自动同步客户端,包括创建表并在数据库尚不存在时填充数据。
// 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);
在本期EF Core 社区站立会议上,团队与创建者Sébastien Pertus进行了对话,他分享了该项目的历史,并演示了几个场景,说明了该框架使用起来是多么快速和容易。
您可以在以下链接中找到节目中提到的相关内容:
https://www.theurlist.com/efcore-standup-2020-09-02
对 EF 核心团队有任何反馈意见?请提交问题或加入我们的众多在线讨论之一。
文章来源:https://dev.to/dotnet/synchronize-databases-with-only- Five-lines-of-code-348k