Tutorials ASP.NET Core Complete Tutorial (ShopNest)

EF Core with SQL Server — Advanced Features

Learn EF Core with SQL Server — Advanced Features in our free ASP.NET Core Complete Tutorial (ShopNest) series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
EF Core with SQL Server — Advanced Features — ShopNest
Article 22 of 75 · Module 2: Entity Framework Core · ShopNest Financial Reporting System
Target keyword: ef core sql server advanced · Read time: ~34 min · .NET: 8 / 9 · Project: ShopNest Financial Reporting System

Introduction

ShopNest Financial Reporting needs transactions, resilient connections, JSON columns, hierarchical accounts, and multi-tenant data isolation — SQL Server features EF Core 8 exposes cleanly.

After this article you will

  • Wrap operations in explicit transactions
  • Configure connection retry policies
  • Map JSON columns and temporal tables
  • Design multi-tenant filters
  • Integrate full-text search where needed

Prerequisites

Concept deep-dive

// Explicit transaction
await using var tx = await _db.Database.BeginTransactionAsync();
try
{
    _db.LedgerEntries.Add(debit);
    _db.LedgerEntries.Add(credit);
    await _db.SaveChangesAsync();
    await tx.CommitAsync();
}
catch { await tx.RollbackAsync(); throw; }

// Connection resiliency (Program.cs)
options.UseSqlServer(connectionString, sql =>
    sql.EnableRetryOnFailure(maxRetryCount: 5));

// JSON column (.NET 8 + SQL Server)
public class ReportSnapshot
{
    public int Id { get; set; }
    public ReportMetadata Metadata { get; set; } // mapped to nvarchar(max) JSON
}

// Global query filter — multi-tenancy
modelBuilder.Entity<Order>()
    .HasQueryFilter(o => o.TenantId == _tenantProvider.TenantId);

Temporal tables: SQL Server system-versioned tables — EF Core 8 can map history. Hierarchy: adjacency list or closure table for chart of accounts.

Hands-on — ShopNest Financial Reporting System

  1. Transfer funds service: debit/credit in one transaction.
  2. Enable retry on failure for Azure SQL transient errors.
  3. TenantId column + query filter on financial entities.
  4. Store report config as JSON owned type.

Common errors & best practices

  • Nested SaveChanges without transaction — partial updates on failure.
  • Query filter forgotten in raw SQL — tenant data leak; always filter TenantId.
  • No retry on cloud SQL — transient failures become user-visible 500s.

Interview questions

Q: When explicit transaction?
A: Multiple SaveChanges or cross-context operations must succeed or fail together.

Q: Multi-tenancy with EF?
A: Global query filter on TenantId + set TenantId on insert via interceptor.

Q: EnableRetryOnFailure?
A: Handles transient Azure SQL errors (throttling, failover) automatically.

Summary

  • Transactions ensure atomic financial transfers
  • Retry policies essential for cloud SQL Server
  • JSON columns and query filters support modern reporting
  • Temporal tables and hierarchy for audit and COA

Previous: Database First Approach with EF Core
Next: Dependency Injection in ASP.NET Core

FAQ

Does EF support SQL Server temporal tables?

EF Core 8+ has improved support; configure in Fluent API or scaffold from temporal table.

Global query filter pitfalls?

Must disable filter in admin/migration scenarios with IgnoreQueryFilters().

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ASP.NET Core Complete Tutorial (ShopNest)
Course syllabus
Module 1: Foundations
Module 2: Entity Framework Core
Module 3: Dependency Injection & Middleware
Module 4: Authentication & Security
Module 5: Web API
Module 6: Advanced Architecture
Module 7: Testing
Module 8: Deployment & DevOps
Module 9: Real-World Projects
Module 10: Advanced Topics
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details