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
A property on a nested owned entity is not being saved in the CosmosDB document #31664
Labels
area-cosmos
area-model-building
breaking-change
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Comments
If it is any help, here are the logs for when the property is called Referrer.UserId:
Here are the logs when the property is named 'Referrer.UserIdRenamed':
The important difference seems to be these lines:
|
/cc @AndriySvyryd |
AndriySvyryd
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Oct 2, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 2, 2023
This was referenced Oct 2, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 3, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 3, 2023
ajcvickers
pushed a commit
that referenced
this issue
Oct 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-cosmos
area-model-building
breaking-change
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
While developing our application I have noticed what appears to be some strange behaviour with the Entity Framework CosmosDB provider (we are using the Microsoft.EntityFrameworkCore.Cosmos NuGet package version 6.0.8).
We have a 'User' entity that has a nested owned entity (a referrer), the referrer references the ID of another user entity.
When the user entity is saved, the property on the nested owned entity is not saved at all when the property on the C# record is called 'UserId'. If it is called anything else then it is saved successfully.
I'm not sure if this behaviour is expected or if it is a bug, so I thought it could be worth reporting.
I have managed to replicate the issue in a simplified form in a console app using the code below:
Running this code saves two entities like this, as you can see the second user is missing the '"UserId": "1"' property:
If the 'UserId' on the 'Referrer' C# record is renamed to something else, then it saves as expected:
My guess was that this could be something to do with the way the implicit shadow primary key is working as mentioned here:
https://learn.microsoft.com/en-us/ef/core/modeling/owned-entities#implicit-keys
So I tried adding a key to the nested entity. This saves a 'UserId' property on the referrer, but it saves it with the UserId of the current entity (a 2 instead of a 1):
I also tried adding 'ToJsonProperty("UserId")' on the referrer user ID mapping like this:
However this also results in the wrong ID being saved (2 instead of 1).
I am thinking this must have something to do with the fact that the property on the nested owned entity has the same name as the entity ('User') plus the name of the 'key' property for the main entity ('Id').
The simple workaround is to use a different name for this property (which is what we have done), but it would be good to get an understanding why Entity Framework is behaving this way or if we have done something wrong in the mapping.
The text was updated successfully, but these errors were encountered: