Open Srykr opened 7 years ago
If you have a parent with a single child entity, not a Collection. When you set the state to Deleted, and GetChanges() it does not have changes.
Sample at: https://github.com/Srykr/DeleteChildFromParentTest
Does not have Changes:
[Fact] public void DeleteSingleFromParentOneToOne() { var parentwithSingleChild = new ChangeTrackingCollection<ParentwithSingleChild>( new ParentwithSingleChild { ParentId = 1, ParentName = "ParentName1", Child = new Child { ParentId = 1, ChildId = 1, ChildName = "ChildName2" } }); parentwithSingleChild.First().Child.TrackingState = TrackingState.Deleted; var changes = parentwithSingleChild.GetChanges(); changes.Should().HaveCount(1); }
Has Changes
[Fact] public void DeleteChildFromParentOneToMany() { var parentwithMultipleChildren = new ChangeTrackingCollection<ParentwithMultipleChildren>(new ParentwithMultipleChildren { ParentId = 1, ParentName = "ParentName1", Children = new ChangeTrackingCollection<Child> { new Child { ParentId =1, ChildId = 1, ChildName = "ChildName2" }, new Child { ParentId =1, ChildId = 2, ChildName = "ChildName2" } } }); parentwithMultipleChildren.First().Children.First().TrackingState = TrackingState.Deleted; var changes = parentwithMultipleChildren.GetChanges(); changes.Should().HaveCount(1); }
If I am doing something wrong, please advise as well.
Thank you.
Thanks for the test and repro. I'll have a look to see if this is a bug.
If you have a parent with a single child entity, not a Collection. When you set the state to Deleted, and GetChanges() it does not have changes.
Sample at: https://github.com/Srykr/DeleteChildFromParentTest
Does not have Changes:
Has Changes
If I am doing something wrong, please advise as well.
Thank you.