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

DbSet names are not used for table names in TPT and TPC mappings #28193

Closed
ajcvickers opened this issue Jun 9, 2022 · 2 comments · Fixed by #28359
Closed

DbSet names are not used for table names in TPT and TPC mappings #28193

ajcvickers opened this issue Jun 9, 2022 · 2 comments · Fixed by #28359
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

ajcvickers commented Jun 9, 2022

This never mattered before because TPT required explicit table naimg. Now, with UseTptMappingStrategy and UseTpcMappingStrategy, it does matter.

For example:

public abstract class Animal
{
    public int Id { get; set; }
    public string Species { get; set; }
}

public class FarmAnimal : Animal
{
    public decimal Value { get; set; }
}

public abstract class Pet : Animal
{
    public string Name { get; set; }
}

public class Cat : Pet
{
    public string EdcuationLevel { get; set; }
}

public class Dog : Pet
{
    public string FavoriteToy { get; set; }
}

public class SomeDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(Your.ConnectionString)
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    
    public DbSet<Animal> Animals { get; set; }
    public DbSet<Cat> Cats { get; set; }
    public DbSet<Dog> Dogs { get; set; }
    public DbSet<FarmAnimal> FarmAnimals { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Animal>().UseTpcMappingStrategy();
    }
}

The tables are:

      CREATE TABLE [Cat] (
          [Id] int NOT NULL,
          [Species] nvarchar(max) NULL,
          [EdcuationLevel] nvarchar(max) NULL,
          [Name] nvarchar(max) NULL,
          CONSTRAINT [PK_Cat] PRIMARY KEY ([Id])
      );

      CREATE TABLE [Dog] (
          [Id] int NOT NULL,
          [Species] nvarchar(max) NULL,
          [FavoriteToy] nvarchar(max) NULL,
          [Name] nvarchar(max) NULL,
          CONSTRAINT [PK_Dog] PRIMARY KEY ([Id])
      );

      CREATE TABLE [FarmAnimal] (
          [Id] int NOT NULL,
          [Species] nvarchar(max) NULL,
          [Value] decimal(18,2) NOT NULL,
          CONSTRAINT [PK_FarmAnimal] PRIMARY KEY ([Id])
      );
@smitpatel
Copy link
Member

Interestingly #27947

@ajcvickers
Copy link
Member Author

@smitpatel For TPC, the DbSets are not for abstract types, but this still doesn't work. Interesting conflict of interest, though. 🤷

@ajcvickers ajcvickers added this to the 7.0.0 milestone Jun 15, 2022
@AndriySvyryd AndriySvyryd removed their assignment Jul 2, 2022
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 2, 2022
AndriySvyryd added a commit that referenced this issue Jul 2, 2022
Use DbSet names for TPC and TPT entity types

Fixes #28193
Fixes #29298
AndriySvyryd added a commit that referenced this issue Jul 2, 2022
Use DbSet names for TPC and TPT entity types

Fixes #28193
Fixes #29298
AndriySvyryd added a commit that referenced this issue Jul 7, 2022
Use DbSet names for TPC and TPT entity types

Fixes #28193
Fixes #28298
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview7 Jul 10, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview7, 7.0.0 Nov 5, 2022
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. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants