views:

68

answers:

1

In the constructor of each of my POCO's I have this:

this.StartTracking();

To ensure that tracking is turned on for every instance of one of my POCO's. I have an Entity A which contains a TrackableCollection of Entity B. When I load my instance of Entity A like such:

using(MyContext ctx = new MyContext())
{
    entityA = ctx.EntityA.Include("EntityB").Where(x => x.Id== id).FirstOrDefault();
}

Looking at the ObjectsAddedToCollection property on Entity A, there is 1 object flagged as 'Unchanged'. When I do entityA.EntityB[0].MarkAsDeleted(), the state does not get set to 'Deleted' and moved to the ObjectsRemovedFromCollection collection. It just gets removed altogether. I double checked and the ChangeTrackingEnabled is set to True for both Entity A and Entity B. Is there a reason why this is not working? Because of this I cannot delete child entity and persist the changes to the database.

+1  A: 

This appears to be a bug. In the method RecordRemovalFromCollectionProperties I changed the line that simply returns to:

if(((IObjectWithChangeTracker) value).ChangeTracker.State == ObjectState.Added)
    return;

This fixed the issues I was having.

Brandon