Relational Db
Last updated
// Register both in DI
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddFlexDapper(options =>
{
options.ConnectionString = connectionString;
options.ProviderName = "SqlServer";
});
// Use EF Core for writes
public class OrderService
{
private readonly ApplicationDbContext _context;
private readonly IFlexMicroOrmRepository _dapper;
// Write with EF Core (change tracking, transactions)
public async Task CreateOrderAsync(Order order)
{
_context.Orders.Add(order);
await _context.SaveChangesAsync();
}
// Read with Dapper (high performance)
public async Task<IReadOnlyList<OrderSummary>> GetOrderSummariesAsync()
{
return await _dapper.QueryAsync<OrderSummary>(
"SELECT * FROM OrderSummariesView");
}
}