EF Core + Data Access with Copilot
EF Core 10 + Copilot on an enterprise schema you don't own — scaffolding, LINQ performance, migrations, and the repo-vs-DbContext decision Halcyon's team has to make.
About This Course
Learn to use GitHub Copilot in Visual Studio 2026 against real enterprise schemas you do not own, using Entity Framework Core 10. This course teaches scaffolding EF Core from an existing database with dotnet ef dbcontext scaffold against AdventureWorks, the LINQ-to-SQL patterns Copilot gets wrong without grounding (N+1 queries, projection, split queries, AsNoTracking), migrations on a shared enterprise database (idempotent SQL scripts, review workflow, rollback strategies), and the Repository / Unit-of-Work / Specification decision Halcyon's team has to make on every data-access PR. By the end you will be able to reverse-engineer a production schema into a maintainable DbContext, use Copilot Edits + the @debugger agent to find and fix an N+1 under live SQL trace, and ship a feature-migration PR with a Copilot-generated review walkthrough.
Course Curriculum
7 Lessons
Scaffolding EF Core from an existing database
Teaching lesson on reverse-engineering a DbContext from an existing SQL Server schema via dotnet ef dbcontext scaffold. Covers the data-annotations vs fluent-API trade-off, the partial-class escape hatch that preserves customizations across re-scaffolds, --table / --schema narrowing, and how to ground Copilot on team naming + convention rules so re-scaffolds don't fight the review.
Reverse-engineer the AdventureWorks Sales schema with Copilot
Dana opens the Halcyon.Adventure.Data starter in VS 2026, signs into GHE, and scaffolds the Sales.Customer, Sales.SalesOrderHeader, and Sales.SalesOrderDetail entities from the local AdventureWorks2025 database via dotnet ef dbcontext scaffold. Students use Copilot Ask mode to review the generated DbContext against Halcyon's convention file, apply narrow customizations through partial classes (so re-scaffolds survive), and open a PR with a Copilot-generated commit message + review summary.
LINQ-to-SQL patterns Copilot gets wrong
Teaching lesson on the EF Core patterns Copilot gets wrong without grounding — the N+1 problem, Cartesian explosion from naive Include().ThenInclude(), when AsSplitQuery() is the fix vs when projection is, AsNoTracking for read-only queries, and projecting with Select(new {...}) to load only the columns the view actually needs. Covers how to use the EF Core LogTo + EnableSensitiveDataLogging plus Serilog to see the SQL EF actually generates.
Fix N+1 queries with Copilot and the @debugger agent
Dana's new Customer-with-orders report runs 11 seconds for 10 rows — the classic N+1. Students enable EF Core SQL logging to see the N+1 under the API trace, use the @debugger specialized agent to walk the slow repository call under the live debugger, land the fix via Copilot Edits (Include().ThenInclude().AsSplitQuery() + projection), add a BenchmarkDotNet regression test that fails on the old pattern and passes on the new, and open the PR with a Copilot-generated before/after SQL diff.
EF Core migrations on a shared enterprise database
Teaching lesson on managing EF Core migrations against a database you don't own alone. Covers baseline-from-existing (how to start migrations against a scaffolded schema without clobbering existing data), the idempotent-script workflow for production DBAs who refuse to run dotnet ef database update on prod, the --idempotent flag, the rollback story (dotnet ef database update <PriorMigrationName>), the two-column-rename gotcha where EF's generated migration drops+adds and must be hand-edited to RenameColumn, and the Halcyon review checklist for a migration PR.
Add a Customer-Tier feature to AdventureWorks via migration
Michael Johnston needs a CustomerTier column on Sales.Customer for the acquisition's tiered-pricing rollout. Students design the enum with Copilot Ask mode, add the property via a partial class (so re-scaffolds don't erase it), generate the migration with dotnet ef migrations add AddCustomerTier, review the generated SQL with the @git agent, apply the migration with dotnet ef database update, author a reusable .github/prompts/add-ef-feature.prompt.md prompt file for the next column, and open the PR with a Copilot-generated SQL walkthrough.
Repository, Unit-of-Work, and Specification patterns under grounding
Teaching lesson on the three patterns Copilot defaults to when scaffolding data-access code — Repository, Unit-of-Work, Specification — and when each one actually earns its place in a modern EF Core 10 codebase vs when it's over-engineering. Covers Halcyon's decision table (DbContext IS a Unit-of-Work; Repository only when you need to abstract EF for testability or multiple data sources; Specification only when query reuse across endpoints is a real pain), the copilot-instructions.md rules that keep Copilot aligned with the decision, and the review flags that catch "pattern-y" PRs during code review.