-
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
Replacing a property with owned type doesn't work if there is owned types nesting in v2.1 RC1 #12118
Comments
Just to give a more real life example, here are some of my models (simplified).
|
@AndriySvyryd Any update on the investigation here? Specifically, is it something we might want to patch? |
@ajcvickers The issue here is that when we attach The workaround is to set the dependent after the new owned entity is fixed up: using (var context = new MyDbContext(options))
{
var entity = context.MyEntities.Find(entityId);
Console.WriteLine("MyProperty before changing: " +
entity.Owned.OwnedOwnedProperty.MyProperty);
entity.Owned = new OwnedEntity(null);
context.ChangeTracker.DetectChanges();
context.Entry(entity).Reference(e => e.Owned).TargetEntry.Reference(e => e.OwnedOwnedProperty).CurrentValue
= new OwnedOwnedEntity(4848);
Console.WriteLine("MyProperty before saving changes: " +
entity.Owned.OwnedOwnedProperty.MyProperty);
context.SaveChanges();
Console.WriteLine("MyProperty after saving changes: " +
entity.Owned.OwnedOwnedProperty.MyProperty);
} |
@AndriySvyryd Thanks. Removing milestone to re-triage on Wednesday. /cc @divega |
Note from triage: non-owned case with conflicting FK should throw, but low priority. |
The problem is repeated at the first level of the object, as well as with of one to one relationship. |
Hi everyone. I had similar issue. I was unable to update property of owned type of an entity.
If someone can suggest better approach it would be nice. |
@Alantoo Does it fix the nested own types? I solved using a quick workaround ( We have only one entity with own type so this approach is simpler for us, without using reflexion) Example for detached context:
I`m waiting for a live so I can remove redundant code |
I can confirm that @smariussorin workaround works. =)) Tested with a owned type with 5 nested owned types |
I have this problem as well, although @smariussorin solution did not work for me but @AndriySvyryd solution works perfectly. Do we know when this problem will be resolved so I can remove my temporary work around. Thanks. |
Hi, What's the status of this? Also facing issues with owned types with 2 levels (parent A - owned collection AB - owned collection BC), where, when adding a new entry to AB, which holds also a new entry in BC, all the entries in AB lose their BC values, except the first and the last (newly added) entry. You can see it clearly here (Notice the StatusHistory collections): "id": "51e8e0dc-ef21-46a3-b753-eca90100a005",
"Country": "BEL",
"Discriminator": "ServiceLocation",
"OrganisationId": "7b3c1aec-1e14-4e33-8302-50e3c5ec6e24",
"Location": null,
"Services": [
{
"id": "1c9867c5-18a6-4384-9f14-f3b534ac2835",
"Discriminator": "Service",
"ExternalIdentifier": "1112332223",
"ServiceLocationid": "51e8e0dc-ef21-46a3-b753-eca90100a005",
"StatusHistory": [
{
"id": "3473c8ee-ab48-435a-b938-d4868a383a52",
"Discriminator": "ServiceStatusHistory",
"EndDateTime": "9999-12-31T23:59:59.9999999",
"ServiceStatusEnum": "requested",
"Serviceid": "1c9867c5-18a6-4384-9f14-f3b534ac2835",
"StartDateTime": "2019-01-08T00:00:00Z"
}
]
},
{
"id": "dd6ad486-de1d-420d-809c-6f84245619c9",
"Discriminator": "Service",
"ExternalIdentifier": "1112332235",
"ServiceLocationid": "51e8e0dc-ef21-46a3-b753-eca90100a005",
"StatusHistory": []
},
{
"id": "081f85ef-3a36-41a5-a5f1-d67e79fb2234",
"Discriminator": "Service",
"ExternalIdentifier": "1112332238",
"ServiceLocationid": "51e8e0dc-ef21-46a3-b753-eca90100a005",
"StatusHistory": []
},
{
"id": "31b0b16e-0900-4c67-937c-eb3002563eef",
"Discriminator": "Service",
"ExternalIdentifier": "1112332231",
"ServiceLocationid": "51e8e0dc-ef21-46a3-b753-eca90100a005",
"StatusHistory": [
{
"id": "baa23b25-e088-4fb0-b54c-383ed34cc00d",
"Discriminator": "ServiceStatusHistory",
"EndDateTime": "9999-12-31T23:59:59.9999999",
"ServiceStatusEnum": "requested",
"Serviceid": "31b0b16e-0900-4c67-937c-eb3002563eef",
"StartDateTime": "2019-01-08T00:00:00Z"
}
]
}
],
"_rid": "24kMAKY2M4kFAAAAAAAAAA==",
"_self": "dbs/24kMAA==/colls/24kMAKY2M4k=/docs/24kMAKY2M4kFAAAAAAAAAA==/",
"_etag": "\"00000000-0000-0000-a73c-f2ea6b2e01d4\"",
"_attachments": "attachments/",
"_ts": 1546943331
}``` |
@Mortana89 I think that's actually another manifestation of #13578 |
Yes, I am still waiting for a fix to this. I have temporary workaround code in my BaseContext that I want to remove because it is causing other knock on issues for our software now. Is this Issue being resolved in Core version 3.0? Thanks |
@NickCook-StruMIS This issue is in the 3.0 milestone, which means that it is tentatively planned to be fixed in the 3.0 release. |
I've had this issue and written a post on how we resolved it. I hope this helps someone else. |
Just an update, not working in Preview 3, still throws the following exception when replacing an owned owned type with a new one: |
@vertonghenb The fix will be shipped in 3.0 preview 4 |
None of the workarounds work when using Does someone have this use case, and has a small snippet of working code to share? e.g. // `User` is entity
// `User.Token` is owned type
// `User.Token.Hash` is owned-owned type
user.Token = someNewToken;
await userManager.UpdateAsync(user);
// user.Token and user.Token.Hash are not updated I posted by use case to SO here. |
Try something like that:
|
@AndriySvyryd currently I'm using ef core 5 preview and still have the same issue which @andriysavin mentioned earlier. |
@m-okhovat This issue was fixed in 3.0.0, if you are still experiencing it in 5.0.0 file a new issue with a small repro project |
I'm not sure if this is the same issue, but Added a failing test case in #24504 |
@virzak That's by design, you need to traverse navigations by calling |
I'm trying to use replacing properties with owned types since it was promised to fix in 2.1. This feature seems to be working ok with 1 level of owned types nesting. However, if you have 2 nested owned types, EF discards changes on the entity property. Its better to provide an example:
The output I'm getting:
The text was updated successfully, but these errors were encountered: