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

Unable to set a property to null with lazy loading enabled #21287

Closed
arabasso opened this issue Jun 16, 2020 · 1 comment
Closed

Unable to set a property to null with lazy loading enabled #21287

arabasso opened this issue Jun 16, 2020 · 1 comment

Comments

@arabasso
Copy link

I'm running the following code:

...
var customer = context.Find<Customer>(viewModel.CustomerId);

if (viewModel.StatusId == 0)
{
    customer.Status = null;
}

else
{
    customer.Status = context.Find<CustomerStatus>(viewModel.StatusId);
}

context.Update(customer);
context.SaveChanges();
...

Does not work. It only works if I explicitly load the property:

var customer = context.Find<Customer>(viewModel.CustomerId);

context.Entry(customer).Reference(m => m.Status).Load();

if (viewModel.StatusId == 0)
{
    customer.Status = null;
}

else
{
    customer.Status = context.Find<CustomerStatus>(viewModel.StatusId);
}

context.Update(customer);
context.SaveChanges();

Steps to reproduce

  • Enable lazy loading with UseLazyLoadingProxies

Further technical details

EF Core version: 3.1.5
Database provider: Pomelo.EntityFrameworkCore.MySql or MySql.Data.EntityFrameworkCore
Target framework: .NET Core 3.1
Operating system: Windows 10 Pro 2004
IDE: Visual Studio 2019 16.6.2

@ajcvickers
Copy link
Member

Duplicate of #14086

@ajcvickers ajcvickers marked this as a duplicate of #14086 Jun 16, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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