Description
After we upgraded from EF Core 3.0 to EF Core 5.0, we experience some strange behavior when using the EntityTypeBuilder.Ignore method.
Everything worked as expected when we used the following EntityTypeConfigurations with EF Core 3.0.
But a TempId shadow property is added to the generated sql query since we upgraded to EF Core 5.0.
While researching this we temporarily put the 2 configurations below in the same file.
public class ExternalGroupConfiguration : IEntityTypeConfiguration<ExternalGroup>
{
public void Configure(EntityTypeBuilder<ExternalGroup> builder)
{
builder.HasKey(t => t.Key);
builder.Ignore(t => t.Groups);
}
}
public class GroupConfiguration : IEntityTypeConfiguration<Group>
{
public void Configure(EntityTypeBuilder<Group> builder)
{
builder.HasKey(t => t.Key);
builder.Ignore(t => t.ExternalGroups);
}
}
What we've found is that the TempId disappears when we put the GroupConfiguration before the ExternalGroupConfiguration.
public class GroupConfiguration : IEntityTypeConfiguration<Group>
{
public void Configure(EntityTypeBuilder<Group> builder)
{
builder.HasKey(t => t.Key);
builder.Ignore(t => t.ExternalGroups);
}
}
public class ExternalGroupConfiguration : IEntityTypeConfiguration<ExternalGroup>
{
public void Configure(EntityTypeBuilder<ExternalGroup> builder)
{
builder.HasKey(t => t.Key);
builder.Ignore(t => t.Groups);
}
}
I've added a project to reproduce this.
ReproduceTempId.zip
Sidenote: Not changing the order of the configurations, but using the [NotMapped] attribute on the ExternalGroups property in the Group class, does also get rid of the TempId.
public class Group
{
public Guid Key { get; set; }
protected Group()
{
}
[NotMapped]
public virtual IReadOnlyCollection<ExternalGroup> ExternalGroups { get; set; }
}
EF Core version: 5.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0 (in the reproduce project, but .NET Core 3.1 in our original codebase where the problem occurrs)
Operating system: Windows 10 Pro
IDE: Visual Studio 2019 16.9.0