-
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
OwnsMany throws InvalidOperationException on SaveChanges with multiple items in list #15600
Comments
@dave-hillier Question from triage: with regard to this code: image.HasForeignKey("DistributorId");
image.Property<int>("Id");
image.HasKey("DistributorId", "Id"); Is this something that you are doing because you want and value this kind of composite key and relationship in the database? Or is it just that this was what was shown in the blog\docs? |
I put this example together from the EF Core docs The docs state:
The way it's written, it looks like guidance. I was struggling to get the same owned class to work from different places. I get a duplicate key exception but I assume I am doing something wrong. My intention was to get the documented example working first then go back to my code. |
@dave-hillier And is that statement from the docs something you would have expected and wanted in this case? |
@dave-hillier To be fully transparent, I think it's unnecessary and overly complex, but I'm the only one on the team who thinks that. Others assert that this is the normal pattern for this case and something that people will expect and want. |
I have removed it from my code, but I still have a different problem. This other problem I'm unable to make a simple but it seems related (why I mention it here). When I have two classes using the same owned class I either get cast exceptions or duplicate keys. As a workaround, I've now got a copy of the owned entity e.g. |
@dave-hillier Thanks for the additional info. We will discuss again and get back to you. |
More info. The parent classes keys differ. This seems to be a cause. I can make them the same and this exception goes away, though the duplicate keys one still persists.
|
Poaching... |
In the examples for "Owned Entities" there is no example of OwnsMany's usage.
I've put together what I thought was a sensible way of using it, but it doesnt not appear to work as I would expect. See below for the code example.
Steps to reproduce
Further technical details
EF Core version: 2.2.0
InMemoryDatabase
The text was updated successfully, but these errors were encountered: