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

TPT: Additional migrations drop base entity columns from derived entity table #21961

Closed
eraffel-MDSol opened this issue Aug 6, 2020 · 1 comment · Fixed by #22026
Closed
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 type-bug
Milestone

Comments

@eraffel-MDSol
Copy link

eraffel-MDSol commented Aug 6, 2020

Basically the title. Not sure if I'm wiring up TPT correctly, but If I create a model using TPT with base and derived classes, the first migration is what I'd expect, creating the tables. If I add a second migration, it tries to drop the columns on the base table from the table for the derived class.

Sidenote; I'm using the 3.1.6 EF Core tools (dotnet-ef), so if that might be it, let me know.

Steps to reproduce

  1. Create an app with following DbContext, and the latest preview or daily EF packages (I've tested on 5.0.0-preview.8.20365.2 and 5.0.0-rc.1.20406.1)
  2. Add the initial migration.
  3. Add another migration

The second migration will try to drop BaseName from the Parent table

    public class MyContext : DbContext
    {
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Parent>().ToTable("Parent");
            modelBuilder.Entity<ParentBase>().ToTable("ParentBase").HasKey(a => a.Id);
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlServer("Server=localhost;Database=Test;Trusted_Connection=True;");
        }
    }

    public abstract class ParentBase
    {
        public virtual Guid Id { get; set; }

        public string BaseName { get; set; }
    }

    public class Parent : ParentBase
    {
        public string Name { get; set; }
    }

Further technical details

EF Core version: 5.0.0-rc.1.20406.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.6.5

@AndriySvyryd AndriySvyryd self-assigned this Aug 7, 2020
@ajcvickers ajcvickers added this to the 5.0.0 milestone Aug 7, 2020
@AndriySvyryd AndriySvyryd removed their assignment Aug 12, 2020
@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 Aug 12, 2020
@ghost ghost closed this as completed in #22026 Aug 12, 2020
@eraffel-MDSol
Copy link
Author

just checked the latest nuget package package. looks good! Thanks!

@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-rc1 Aug 14, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-rc1, 5.0.0 Nov 7, 2020
This issue was closed.
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 type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants