// Demonstrates: Schema Sync → Cross-Context Query → Parallel Command Commit
using Core.Data.EF.Model.Model;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Core.Data.EF.Context.Context;
using Microsoft.EntityFrameworkCore;
using DataArc;
using DataArc.Abstractions;
internal class Program
{
static readonly IDatabaseDefinitionBuilder _databaseDefinitionService;
static readonly IAsyncDatabaseCommandBuilder _databaseCommandBuilder;
static readonly IAsyncDatabaseQueryBuilder _databaseQueryBuilder;
private static int batchSize = 10000;
static Program()
{
ILoggerFactory factory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
// Register DataArc Orchestration with EF Core contexts
var dataProvider = new ServiceCollection()
.AddLogging()
.AddDataArcCore(ctx =>
{
ctx.AddDbContextPool<DatabaseContextReadCommitted>(options => options
.UseSqlServer("Server=MSI;Database=DatabaseContextReadCommitted.Arc8;Integrated Security=SSPI;TrustServerCertificate=True;Persist Security Info=True")
.EnableSensitiveDataLogging()
.UseLoggerFactory(factory));
ctx.AddDbContextPool<DatabaseContextReadUncommitted>(options => options
.UseSqlServer("Server=MSI;Database=DatabaseContextReadUncommitted.Arc8;Integrated Security=SSPI;TrustServerCertificate=True;Persist Security Info=True")
.EnableSensitiveDataLogging()
.UseLoggerFactory(factory));
ctx.AddDbContextPool<DatabaseContextRepeatableRead>(options => options
.UseSqlServer("Server=MSI;Database=DatabaseContextRepeatableRead.Arc8;Integrated Security=SSPI;TrustServerCertificate=True;Persist Security Info=True")
.EnableSensitiveDataLogging()
.UseLoggerFactory(factory));
ctx.AddDbContextPool<DatabaseContextSerializable>(options => options
.UseSqlServer("Server=MSI;Database=DatabaseContextSerializable.Arc8;Integrated Security=SSPI;TrustServerCertificate=True;Persist Security Info=True")
.EnableSensitiveDataLogging()
.UseLoggerFactory(factory));
})
.BuildServiceProvider();
_databaseDefinitionService = dataProvider.GetService<IDatabaseDefinitionBuilder>()!;
_databaseCommandBuilder = dataProvider.GetService<IAsyncDatabaseCommandBuilder>()!;
_databaseQueryBuilder = dataProvider.GetService<IAsyncDatabaseQueryBuilder>()!;
}
static async Task ExecuteMain()
{
// SCHEMA CREATION
var db = _databaseDefinitionService
.UseContext<DatabaseContextReadCommitted>()
.UseContext<DatabaseContextReadUncommitted>()
.UseContext<DatabaseContextSerializable>()
.UseContext<DatabaseContextRepeatableRead>()
.Build(applyChanges: true, generateScripts: true);
db.ExecuteDrop();
db.ExecuteCreate();
// QUERY ACROSS CONTEXTS
var data = await _databaseQueryBuilder
.UseQueryContext<DatabaseContextReadCommitted, PrimaryEntityExample>(p => p.Id == 1)
.Join<DatabaseContextReadUncommitted, ForeignEntityExample>(
bag => bag.Get<PrimaryEntityExample>()!.Id, f => f.PrimaryEntityExampleId)
.Select(bag => new ForeignEntityExample()
{
Name = bag.Get<ForeignEntityExample>()!.Name,
Surname = bag.Get<ForeignEntityExample>()!.Surname,
Salary = bag.Get<ForeignEntityExample>()!.Salary,
Notes = bag.Get<ForeignEntityExample>()!.Notes,
Status = bag.Get<ForeignEntityExample>()!.Status
}).ToListAsync();
// BUILD COMMAND PIPELINES
var commandBuilder = await _databaseCommandBuilder
.UseCommandContext<DatabaseContextReadCommitted>()
.Add(new PrimaryEntityExample() { Name = "Name", Description = "Description" })
.AddBulk(data, batchSize)
.UseCommandContext<DatabaseContextReadUncommitted>()
.Add(new PrimaryEntityExample() { Name = "Name", Description = "Description" })
.AddBulk(data, batchSize)
.UseCommandContext<DatabaseContextSerializable>()
.Add(new PrimaryEntityExample() { Name = "Name", Description = "Description" })
.AddBulk(data, batchSize)
.UseCommandContext<DatabaseContextRepeatableRead>()
.Add(new PrimaryEntityExample() { Name = "Name", Description = "Description" })
.AddBulk(data, batchSize)
.BuildAsync();
// PARALLEL EXECUTION
var result = await commandBuilder.ExecuteParallelAsync();
if (result.Success)
{
Console.WriteLine("Bulk insert operations completed successfully.");
}
}
private static void Main(string[] args)
{
ExecuteMain().GetAwaiter().GetResult();
}
}
This example shows complete orchestration — schema generation, cross-context querying, and parallel commits — all managed through DataArc Orchestration.