Skip to content
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

Return true for IsModified on navigations pointing to Added or Deleted entities #21259

Merged
merged 1 commit into from
Jun 15, 2020

Conversation

ajcvickers
Copy link
Member

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

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.
@ajcvickers ajcvickers requested a review from a team June 14, 2020 21:16
@ajcvickers ajcvickers merged commit 48a92c7 into master Jun 15, 2020
@ajcvickers ajcvickers deleted the RTJ4_0614 branch June 15, 2020 15:09
@kipusoep
Copy link

kipusoep commented Sep 13, 2023

Hi @ajcvickers, I just found this PR via #16513 and I'm afraid this does not work anymore in EFCore 7.0.9.
I have an entity, let's assume it's called MainEntity, which has an owned entity property called OwnedEntity. When I assign a newly constructed object to the OwnedEntity property, the MainEntity is not marked as modified.
Example:

class MainEntity
{
    public OwnedEntity OwnedEntity { get; set; }
}

[Owned]
class OwnedEntity
{
    // Some properties
}

var mainEntity = await _context.MainEntities.SingleOrDefaultAsync(x => x.Id == 1);
mainEntity.OwnedEntity = new OwnedEntity {
    // Some properties
};
var state = _context.Entry(mainEntity).State;

// state == Unchanged

This should not be the case right?

@kipusoep
Copy link

Hmm my bad, I didn't notice this was only for the reference instead of the owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detecting if an owned entity was changed
3 participants