Entity Framework Core Interview Question #95
How do you map an entity to a database schema in EF Core?
Migrations, Database Schema & Data Management Mid-Level Intermediate
Quick Interview Answer
For databases that support schemas, EF Core can map a table to a named schema. This can help organize database objects or integrate with an existing database design.
Detailed Explanation
For databases that support schemas, EF Core can map a table to a named schema. This can help organize database objects or integrate with an existing database design.
A default schema can also be configured for model objects that do not specify one explicitly.
Schema behavior varies by provider, so applications intended to support multiple database engines should account for provider differences.
Code Example
modelBuilder.HasDefaultSchema("app");
modelBuilder.Entity<AuditLog>()
.ToTable("AuditLogs", "audit");