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
Detecting if an owned entity was changed #16513
Comments
Note for triage: this is interesting because in the code below, the change to the owned property is a delete/add operation, not an update operation. The Maybe if the entity state is Post post = new Post();
post.Address = new Address {Street = "At the mall", Zip = "01187"};
context.Posts.Add(post);
context.SaveChanges();
Address newAddress = new Address {Street = "Updated", Zip = "Updated"};
post.Address = newAddress;
MemberEntry memberEntry = context.Entry(post).Member(nameof(Post.Address));
Console.WriteLine(memberEntry.IsModified); |
Notes from triage: putting this on the backlog as a bug. However, note that in this case it will be an update because of the way owned types work. But if the relationship is identifying, then we don't mark the FK as modified. We should investigate this space. |
I may have found other points of interest. They are not about owned entity types but may still be related. |
I investigated this some more and I now understand why this was labeled a bug. Collection navigations already have this behavior--that is, Deleted or Added related entities indicate that the navigation property is modified. So this change brings reference navigations inline, which I think is a bug. Nevertheless, I think it makes sense to document this as a breaking change. |
…d entities Fixes #16513 I investigated this some more and I now understand why this was labeled a bug. Collection navigations already have this behavior--that is, Deleted or Added related entities indicate that the navigation property is modified. So this change brings reference navigations inline, which I think is a bug. Nevertheless, I think it makes sense to document this as a breaking change.
…d entities (#21259) Fixes #16513 I investigated this some more and I now understand why this was labeled a bug. Collection navigations already have this behavior--that is, Deleted or Added related entities indicate that the navigation property is modified. So this change brings reference navigations inline, which I think is a bug. Nevertheless, I think it makes sense to document this as a breaking change.
Description
When I have an entity that ownes another entity and access the IsModified-Property on the corresponding MemberEntry for the owned type, after modifying it, it always returns false.
We wanted to use the IsModified-Property to detect whether a property has changed and create change sets to later revert the entity to it's former state. It is working for all property entries but not with owned ones.
Is there a way to detect if an owned entity was changed using EF Core?
Steps to reproduce
I've included an ASP.Net MVC Application. The logic to reproduce the scenario is inside of the HomeController inside of the Index-Action
owned_entity_types_is_modified_asp_net_core_mvc.zip
Further technical details
EF Core version: 2.1.1
Database Provider: In-Memory
Operating system: Windows 10 Pro - Version 1809
IDE: Visual Studio 2017 15.9.7
The text was updated successfully, but these errors were encountered: