-
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
Throw early when user mistakenly uses OwnsOne() but points to a collection #20303
Comments
How do we test if a property represents a collection? We can know it isn't a collection if it doesn't implement |
This is more of a placeholder for me. It's meant to cover both the |
@AndriySvyryd Re the remaining part - throwing for This line in Navigation.IsCompatible() is where we are returning However I could at this point add in some lines which check whether we are only failing this because of multiplicity i.e. whether Then when we try to build the But to do that I would need to update a few of the |
@lajones Why can't you call |
It's coming through this line which only sets shouldThrow to |
I thought we were talking about the case where user calls |
Sorry - let me be more clear. The test case looks like this where note we are calling modelBuilder.Entity<OneToManyNavPrincipalOwner>()
.OwnsOne<OwnedOneToManyNavDependent>(
"OwnedDependents");
modelBuilder.Entity<OneToManyNavPrincipalOwner>()
.Navigation("OwnedDependents"); Ideally we'd throw in Currently the While this line is called through So I'd like to record, as we go through this code "I tried to set up a |
So the problem in this case is that modelBuilder.Entity<OneToManyNavPrincipalOwner>()
.OwnsOne<OwnedOneToManyNavDependent>(
"OwnedDependents"); Is not creating a navigation. This code should either create a navigation or throw.
This would produce a lot of noise in the model. There's nothing |
OK. Will implement that. Thanks. |
If the user mistakenly uses
OwnsOne()
on a collection orOwnsMany()
on a reference we should point this out with an error message.E.g. see
efcore/test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs
Line 1394 in 112b606
If you change that line to an
OwnsOne()
call instead, theNonGenericString
version of the test eventually fails but with an unhelpful error message deep in the code. Some of the other (Generic
/NonGeneric
etc) OwnedTypes Navigation tests actually pass.We should throw in that situation providing a helpful error message as early as possible.
The text was updated successfully, but these errors were encountered: