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

Unexpected TempId when using EntityTypeBuilder.Ignore #24521

Closed
GJBisschop opened this issue Mar 26, 2021 · 4 comments · Fixed by #25263
Closed

Unexpected TempId when using EntityTypeBuilder.Ignore #24521

GJBisschop opened this issue Mar 26, 2021 · 4 comments · Fixed by #25263
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

@GJBisschop
Copy link

GJBisschop commented Mar 26, 2021

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

@ajcvickers
Copy link
Member

/cc @AndriySvyryd to look for dupe.

@AndriySvyryd
Copy link
Member

Could be a duplicate of #18388

@GJBisschop
Copy link
Author

Is there any estimate as to when this issue will be resolved?

@ajcvickers
Copy link
Member

@GJBisschop This issue is in the 6.0 milestone, which means we plan to fix it for the 6.0 release. See the planning process.

@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 14, 2021
@AndriySvyryd AndriySvyryd removed their assignment Jul 14, 2021
AndriySvyryd added a commit that referenced this issue Jul 14, 2021
… inverse

Rerun KeyDiscoveryConvention when a property is ignored
Remove the associated FK when a skip navigation is removed
Add IForeignKeyNullNavigationSetConvention
Sort IEntityTypeConfiguration applied from assembly

Fixes #18388
Fixes #24521
AndriySvyryd added a commit that referenced this issue Jul 14, 2021
… inverse

Rerun KeyDiscoveryConvention when a property is ignored
Remove the associated FK when a skip navigation is removed
Add IForeignKeyNullNavigationSetConvention
Sort IEntityTypeConfiguration applied from assembly

Fixes #18388
Fixes #24521
AndriySvyryd added a commit that referenced this issue Jul 16, 2021
… inverse

Rerun KeyDiscoveryConvention when a property is ignored
Remove the associated FK when a skip navigation is removed
Add IForeignKeyNullNavigationSetConvention
Sort IEntityTypeConfiguration applied from assembly

Fixes #18388
Fixes #24521
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 12, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc1, 6.0.0 Nov 8, 2021
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