'Scaffold-DbContext ignores table after updating to EF Core tools 6.0.5
After updating from EF Core Tools 5 to EF Core tools (Microsoft.EntityFrameworkCore.Tools) 6.0.5 I noticed that when running Scaffold-DbContext, a table in the database is completely ignored and no class for it is being generated. The database structure is rather complex so I don't know what exactly causes this problem but the class which was generated in previous versions of the EF Core tools looked like this:
public partial class TableName
{
public string Id { get; set; }
public int TypeId { get; set; }
public virtual RelatedTable1 Related1 { get; set; }
public virtual RelatedTable2 Related2 { get; set; }
}
When inspecting the generated code in OnModelCreating, I found out that the tools are in fact aware of the existence of this table. For example, in the modelBuilder code for another table which is related to the missing table, a UsingEntity call like this is being added:
entity.HasMany(d => d.Types)
.WithMany(p => p.Related1)
.UsingEntity<Dictionary<string, object>>(
"TableName",
l => l.HasOne<RelatedTable2>().WithMany().HasForeignKey("TypeId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("TBL_..."),
r => r.HasOne<RelatedTable1>().WithMany().HasForeignKey("Id").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("TBL_..."),
j =>
{
j.HasKey("Id", "TypeId");
j.ToTable("...");
j.HasIndex(new[] { "TypeId" }, "IX_T..._type_ID");
j.IndexerProperty<string>("Id").HasMaxLength(50).HasColumnName("id");
j.IndexerProperty<int>("TypeId").HasColumnName("type_ID");
});
Why does it decide to do this instead of generating a class for this table? Did anyone experience similar problems like this and has an idea what causes this problem and what can be done about it?
UPDATE:
After looking through the breaking changes in EF Core 6, I found this change which might be exactly what causes this problem in my project. However, I don't yet fully understand how I am supposed to update my code so I don't have to downgrade again or add any additional steps to do every time I run Scaffold-DbContext again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
