Using latest version (February 6th) of LLBLGen 2.6, using Adapter.
I have a question about the following code, taken from the UnitOfWork2 class.
/// <summary>
/// Adds the passed in object for delete. This is the actual routine performing the work.
/// </summary>
/// <param name="entityToDelete">Entity to delete.</param>
/// <param name="restriction">Restriction.</param>
/// <param name="append">If true (default), append the entity at the end of the list, otherwise insert it at the front. False in the case
/// of inserting objects from collections marked for deletion.</param>
internal bool AddForDelete(IEntity2 entityToDelete, IPredicateExpression restriction, bool append)
{
bool accept = false;
UnitOfWorkElement2 newElement = null;
if(!entityToDelete.IsNew)
{
if(!_objectIDsToDelete.ContainsKey(entityToDelete.ObjectID))
{
// accept
accept = true;
newElement = new UnitOfWorkElement2(entityToDelete, restriction);
_objectIDsToDelete.Add(entityToDelete.ObjectID, newElement);
if(append)
{
_entitiesToDelete.Add(newElement);
}
else
{
_entitiesToDelete.Insert(0, newElement);
}
}
}
else
{
// check if this entity is added for save as well. if so, remove it from the save queue.
if(_objectIDsToSave.ContainsKey(entityToDelete.ObjectID))
{
UnitOfWorkElement2 element = _objectIDsToSave[entityToDelete.ObjectID];
_objectIDsToSave.Remove(entityToDelete.ObjectID);
_entitiesToSave.Remove(element);
}
}
return accept;
}
I'm passing in a new entity with the primary key set, like so:
unitOfWork.AddForDelete(new SensitivityPriceGroupEntity() { Id = sensPriceGroupId });
But given that the entity is new, the method returns without having added the entity to the delete queue. Hence nothing gets deleted. I was expecting this to be added to the Unit of Work, and on commit result in the deletion of the SensitivityPriceGroup row with primary key equal to sensPriceGroupId. What's going on?
Incidentally, SensitivityPriceGroupEntity is in a target-per-entity hierarchy and inherits from SensitivityEntity, which is why I'm not deleting it by calling DeleteEntitiesDirectly (I was, until I discovered that the Sensitivity rows weren't getting deleted).