Skip to content
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

HasDefaultSchema is ignored for tables created with TPC mapping #30039

Closed
Dubzer opened this issue Jan 12, 2023 · 1 comment
Closed

HasDefaultSchema is ignored for tables created with TPC mapping #30039

Dubzer opened this issue Jan 12, 2023 · 1 comment

Comments

@Dubzer
Copy link

Dubzer commented Jan 12, 2023

File a bug

I've been trying to configure TPC mapping with EF Core 7.0.2 and seem to encounter the following bug:

When applying .UseTpcMappingStrategy() to the entity, which is an abstract class, all defined children ignore previously specified modelBuilder.HasDefaultSchema().
Although I only checked with PostgreSQL, I've tried to debug this and I'm pretty sure it should be reproducible with any DBMS.

Minimal repro code

using Microsoft.EntityFrameworkCore;

public abstract class SomeEntity { public int Id { get; set; } }
public class SomeChildEntity : SomeEntity { }
public class OtherEntity { public int Id { get; set; } }

public class TestContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("Host=localhost;Port=49153;Database=test;Username=postgres;Password=postgrespw");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("test_schema");
        modelBuilder.Entity<SomeEntity>().UseTpcMappingStrategy();
        modelBuilder.Entity<SomeChildEntity>();
        modelBuilder.Entity<OtherEntity>();
    }
}

Then run migration

new TestContext().Database.EnsureCreated();

The result of this code should be the following structure, where SomeChildEntity is created in database's default schema instead of specified "test_schema", while OtherEntity is created in expected schema

image

Include provider and version information

EF Core version: 7.0.2
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: net7.0

@roji roji changed the title HasDefaultSchema is ignored for tables created with TCP mapping HasDefaultSchema is ignored for tables created with TPC mapping Jan 12, 2023
@roji
Copy link
Member

roji commented Jan 12, 2023

Duplicate of #29899.

@roji roji marked this as a duplicate of #29899 Jan 12, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants