Skip to content

dotnet ef migrations add freezes #29826

@klinki

Description

@klinki

Hello,

I have problems with migrations freezing. I tried using Local SQL Server and SQLite database, it was freezing with both, so it seems provider independent.

Here is very shortened part of my entities and mapping:

public abstract class Investment 
{
    public int Id { get; set; }
}

public class Bond : Investment 
{
   public virtual ICollection<Coupon> Coupons { get; set; }
} 

public class Stock : Investment 
{
    public virtual ICollection<Dividend> Dividends { get; set; }
}


public abstract class InvestmentYield
{
    public int Id { get; set; }
    public Investment Investment { get; set; }
    public int InvestmentId { get; set; }
}

And now mapping:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        var investment = modelBuilder.Entity<Investment>();
        investment.UseTpcMappingStrategy();

        modelBuilder.Entity<Stock>();
        modelBuilder.Entity<Bond>();

        modelBuilder.Entity<InvestmentYield>().UseTpcMappingStrategy();

        // This is the part of code which causes migrations to freeze.
        // To prevent freezes, remove (or comment) code below:

        var dividend = modelBuilder.Entity<Dividend>();
        dividend.Property(e => e.InvestmentId)
            .HasColumnName("stock_id");

        dividend.HasOne<Stock>()
            .WithMany(s => s.Dividends)
            .HasForeignKey(e => e.InvestmentId);

        var coupon = modelBuilder.Entity<Coupon>();
        coupon.Property(e => e.InvestmentId)
            .HasColumnName("bond_id");

        coupon.HasOne<Bond>()
            .WithMany(b => b.Coupons)
            .HasForeignKey(e => e.InvestmentId);

   }

Here is repo with sample project for reproduction:
https://github.com/klinki/ef-core-issue

Include verbose output

Here is verbose output from dotnet ef migrations add MappingMigration. There is not much to see there, it freezes basically right away.

Using project 'C:\projects\own\ef-tpc\ef-tpc.csproj'.
Using startup project 'C:\projects\own\ef-tpc\ef-tpc.csproj'.
...

Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'ef-tpc'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'AppDbContext'.
Finding DbContext classes in the project...
Using context 'AppDbContext'.

Include provider and version information

EF Core version: 7.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer (same happens also for Microsoft.EntityFrameworkCore.Sqlite, maybe it is provider independent issue)
Target framework: .NET 7
Operating system: Windows 10
IDE: Visual Studio 2022 17.4

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions