I am using Self Tracking Entities with the Entity Framework and for some reason I am now getting an error when making a call to StartTracking() before I make changes to an entity.
My code is as follows:
BusinessUnit BusinessUnitObject = this.settingFacade.GetBusinessUnitByID(idToGet);
BusinessUnitObject.StartTracking();
All this does, is use an ID that we have, use the object context to read from the database, and then start tracking on it straight away.
The error is
Value cannot be null. Parameter name: trackingItem
Upon looking at the actual generated code of Entity Framework, the code throwing the error is:
public static void StartTracking(this IObjectWithChangeTracker trackingItem)
{
if (trackingItem == null)
{
throw new ArgumentNullException("trackingItem");
}
trackingItem.ChangeTracker.ChangeTrackingEnabled = true;
}
The parameter "trackingItem" is null, but I am unsure why.
Has anyone come across this before? I have been using STE's the last couple of months and this is the first time this has happened.
EDIT -------------------
Sorry folks...after a lot of refactoring of my code I have introduced a bug, and the object itself was null, which I was then calling StartTracking() on!