-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TPC mapping strategy not respecting default database schema during migration #29899
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
Confirmed this is a bug with TPC mapping. Relational model with TPC is:
Compare to TPT:
Repro: public abstract class Pet
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Cat : Pet
{
public string EducationLevel { get; set; }
}
public class Dog : Pet
{
public string FavoriteToy { get; set; }
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MySchema");
modelBuilder.Entity<Pet>().UseTpcMappingStrategy();
modelBuilder.Entity<Cat>();
modelBuilder.Entity<Dog>();
}
}
public class Program
{
public static async Task Main()
{
using (var context = new SomeDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var model = context.GetService<IDesignTimeModel>();
await context.SaveChangesAsync();
}
}
} |
ajcvickers
changed the title
TPC and TPH mapping strategies not respecting default database schema during migration
TPC mapping strategy not respecting default database schema during migration
Jan 12, 2023
Poaching |
ajcvickers
added a commit
that referenced
this issue
Feb 5, 2023
ajcvickers
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Feb 5, 2023
ajcvickers
added a commit
that referenced
this issue
Feb 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
File a bug
When using the new
.UseTpcMappingStrategy()
and.UseTphMappingStrategy()
extension methods the default database schema is not respected:Model
DbContext
Migration
Workaround
Explicitly specify the schema either by applying the
TableAttribute
on every inherited class:Or via the Fluent API:
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
The text was updated successfully, but these errors were encountered: