-
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
EF Core 3.0 : Why does it automatically generate a unique index? #15512
Comments
|
But we'll also try just configuring it as non-unique |
@divega @AndriySvyryd Why is it not just two one-to-many relationships? (In other words, what is it that makes these different from a normal reference-only navigation setup, which we configure as one-to-many?) |
@ajcvickers They are detected as one one-to-one relationship and then split into two once we process the data annotations. |
@AndriySvyryd Why 1:1? |
@ajcvickers Because both navigations are not collections |
@AndriySvyryd But isn't this two different relationships? (Since there are two FKs, and each navigation is associated with a different FK. So the two navigations cannot be inverses of the same relationship. Which means we have one unidirectional reference navigation property for each relationship...which means one-to-many because this will work for one-to-many or one-to-one (if used as one-to-one) even if it isn't fully constrained to one-to-one.) I'm clearly missing something critical here, but I don't know what question to ask to figure it out! |
@ajcvickers Yes, that's what should happen, but before the FKs are associated with the navigations they are configured as a single one-to-one relationship and later it becomes a unidirectional one-to-one relationship. |
Talked to @AndriySvyryd in person and agreed that this should be two 1:* relationships and so the correct fix (i.e. not just to avoid a breaking change) is to make the FK not unique. (Note that this may be hard to implement due to the design of the model building pipeline.) Throwing as an ambiguous case would not be the correct fix here; we would only do this if making the correct fix is prohibitively expensive, and we can't come up with anything else. |
I have a
class
(I removed some irrelevant properties)In my
DbContext
Steps to reproduce
In
PMC
run this:After run it, the tool generates the following:
Interestingly, only
ParentCommentID
generates a unique index, whileReplyCommentID
does not. I don't want to specifyIsUnique(false)
in DbContext. So, what exactly is this situation? 😄Further technical details
EF Core version: 3.0.0-preview3.19153.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 1903
IDE: Visual Studio 2019 16.0.2
The text was updated successfully, but these errors were encountered: