-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Copy link
Milestone
Description
File a bug
When using the new .UseTpcMappingStrategy() and .UseTphMappingStrategy() extension methods the default database schema is not respected:
Model
public abstract class Pet
{
public string Name { get; set; }
}
public class Cat : Pet
{
public string EducationLevel { get; set; }
}
public class Dog : Pet
{
public string FavoriteToy { get; set; }
}DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MySchema");
// Uses "MySchema"
modelBuilder.Entity<Pet>()
.UseTptMappingStrategy();
// Uses "dbo"
modelBuilder.Entity<Pet>()
.UseTpcMappingStrategy();
modelBuilder.Entity<Pet>()
.UseTphMappingStrategy();
}Migration
migrationBuilder.CreateTable(
name: "Dogs",
// Omits the 'schema' parameter
columns: table => new { } [...])Workaround
Explicitly specify the schema either by applying the TableAttribute on every inherited class:
[Table("Dogs", Schema = "MySchema")]
public class Dog : PetOr via the Fluent API:
modelBuilder.Entity<Dog>().ToTable("Dogs", "MySchema");Provider and version information
EF Core version: 7.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.5 Preview 2