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

Change detection for null navigations being set to null #14086

Open
pikausp opened this issue Dec 5, 2018 · 2 comments
Open

Change detection for null navigations being set to null #14086

pikausp opened this issue Dec 5, 2018 · 2 comments

Comments

@pikausp
Copy link

pikausp commented Dec 5, 2018

I enabled lazy loading in my project. Say I have the following model

public class BillingInformation {
    public int Id {get;set;}
    public virtual Address Address {get;set;}
}
public class Address {
    public int Id {get;set;}
}

When I set Address property to null, the context does not consider that a change. If I access the property (call its getter) before setting it to null, the entity is marked as modified and the foreign key is set to null in the database.

Further technical details

EF Core version: 2.1.4
Database Provider: Pomelo.EntityFrameworkCore.MySql v2.1.2
Operating system: Windows 10 v1803
IDE: Visual Studio 2017 15.9

@ajcvickers
Copy link
Member

@pikausp There are a couple of reasons why this is the case:

  • Lazy-loading proxies are setup to handle what is needed for lazy-loading. Setting a property to null is a change-tracking behavior, which is being tracked by Implement change tracking proxies #10949. We considered doing this anyway, but...
  • Making this behavior consistent for principal/dependent ends and reference/collection navigation properties is non-trivial. So setting the FK to null for a simple case like above is doable, but deciding what to do when, for example a principal-to-dependent to null is more difficult.

@ajcvickers
Copy link
Member

Reopening this based on discussion here: #19437 (comment). This should be fixed so it works consistently with both change tracking proxies and manually implemented notification entities.

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

No branches or pull requests

2 participants