efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Updates cannot delete navigations with shadow foreign keys in case of explicit tracking

Open z505985755 opened this issue 1 year ago • 4 comments

for example, the current data is a factory with two areas. When using explicit-tracking to transfer this factory, there is one area under this factory. The purpose is to modify the area relationship of the factory so that this factory contains only one area, but in fact the factory area relationship is not modified. This factory still has two area

z505985755 avatar Aug 22 '24 03:08 z505985755

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

roji avatar Aug 22 '24 11:08 roji

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

EFTest.zip I've posted a fully working, minimal console program that shows the problem, please check it out

z505985755 avatar Aug 23 '24 07:08 z505985755

@z505985755 This is by-design--see Explicitly Tracking Entities in the docs. Specifically, there is no way to know that the navigation is null because it was loaded and then set to null, as opposed to just being null because it isn't loaded. The documentation contains various approaches you can take to handle this.

ajcvickers avatar Aug 27 '24 10:08 ajcvickers

@z505985755 This is by-design--see Explicitly Tracking Entities in the docs. Specifically, there is no way to know that the navigation is null because it was loaded and then set to null, as opposed to just being null because it isn't loaded. The documentation contains various approaches you can take to handle this.

@ajcvickers You are right, I understand now. Maybe there should be a convention to indicate that the relationship is deleted, for example, when updating, if the navigation id is negative, it means that the navigation relationship is deleted, or there is another better way.

z505985755 avatar Aug 28 '24 01:08 z505985755