-
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
Don't detect FK properties that match exactly the principal key properties #13274
Comments
@Trapov The problem is that
var accountForPartner = systems.OwnsOne(s => s.AccountForPartners);
accountForPartner.Property<Guid>("OwnedId");
accountForPartner.HasForeignKey("OwnedId"); |
Leaving this open for triage since this is a pretty obscure thing to have to do. |
Triage discussion: we should look into not detecting PKs by convention on owned types, since it is uncommon that an owned type will have an explicitly declared PK. However, we can continue to look for an FK by convention. |
I think I ran into this as well. I created an Owned class for a few common columns all of my tables share with a FK pointing to my Users table. Everything worked fine. until I tried to add that type to my User object. It just silently didn't add the column for the User FK. I had noticed that Owned columns were being prefixed with the property name and I didn't want that so I used the Column attribute to explicitly specify the name and started getting the error from the issue. I tried to demo and summarize my issue on StackOverflow just incase I was doing something wrong. That is here, https://stackoverflow.com/questions/52958737/ef-core-2-1-saying-multiple-columns-have-been-added-to-the-primary-key-but-they Finally, I removed the Owned class property from the "User" class and copy + pasted the columns onto the User class and it worked exactly as expected which makes me think this is a bug with OwnedAttribute and its handling, not my implementation.
|
OwnsOne
is throwing an exception when owned type has the same key name and type, even if the root entity id and the child entity id were marked withHasColumnName
differently.This code was working in the previous version(the latest working version is 2.0.3), but starting from 2.1.0 it doesn't work anymore.
Exception message:
Stack trace:
Steps to reproduce
It throws when you try to add a migration
dotnet ef migrations add [Name]
Further technical details
EF Core version: 2.1.0-2.1.3
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL
Operating system: Windows 10
IDE: Visual Studio 2017 15.8.3
The text was updated successfully, but these errors were encountered: