-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Migrations do not work when an owned type property is called Item #25501
Comments
Duplicate of #25485 |
I tried the daily build containing #25809 and the issue is still there. I have looked a bit at what the code from the migration does and I could reduce the issue to this unit test : [ConditionalFact]
public void Can_own_property_with_clrtypes_name()
{
var modelBuilder = CreateModelBuilder();
var orderEntityBuilder = modelBuilder.Entity("Order", ConfigurationSource.Explicit);
orderEntityBuilder.HasOwnership(new TypeIdentity("MyType"), new MemberIdentity("Other"), ConfigurationSource.Explicit);
orderEntityBuilder.HasOwnership(new TypeIdentity("MyType"), new MemberIdentity("Item"), ConfigurationSource.Explicit);
} The HasOwnership call works correctly with the "Other" MemberIdentity but fails with "Item". It throws the exception seen in the initial report. |
The fix was made to make sure that EF Core never calls |
The repro code is the one in the issue above. After running the command 'dotnet ef migrations add InitialMigration', the migration contains the following code: modelBuilder.Entity("Order", b =>
{
b.OwnsOne("MyItem", "Count", b1 =>
{
// ...
}
} This part of the code is calling the model builder in the same way I did in the previous comment. You can also see in the stacktrace given by the command 'dotnet ef database update' that it calls HasOwnership. |
After migrating a project running from .NET 5 / EFCore 5 to the preview 7 of .NET 6 / EFCore 6, I am unable to run the project because the migration fails. I found out that the cause was an owned type with a property name of 'Item'.
When running the command 'dotnet ef database update', the following error is displayed (full output is below) :
Full command output
To reproduce this error use the program below and run the following commands :
Program that reproduce the error
Having only the ShippingAddress property works correctly as well as renaming the property Item to anything else. It only breaks with the name 'Item'.
EF Core version: 6.0.0-preview.7.21378.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0.100-preview.7.21379.14
Operating system: Windows 10
IDE: Visual Studio 2022 Preview 3
The text was updated successfully, but these errors were encountered: