TrackableEntities / trackable-entities

N-Tier Support for Entity Framework with WCF or ASP.NET Web API
http://trackableentities.github.io
MIT License
120 stars 36 forks source link

GetChanges() Does not have any changes when delete a single child entity #195

Open Srykr opened 7 years ago

Srykr commented 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.

tonysneed commented 7 years ago

Thanks for the test and repro. I'll have a look to see if this is a bug.