public bool Delete(IEnumerable<PartyX> entities)
{
Contract.Requires(entities != null);
Contract.Requires(Contract.ForAll(entities, (PartyX e) => e != null));
Contract.Requires(Contract.ForAll(entities, (PartyX e) => e.Id >= 0));
using (IUnitOfWork uow = this.GetUnitOfWork())
{
IRepository<PartyX> repo = uow.GetRepository<PartyX>();
IRepository<PartyStatus> repoCM = uow.GetRepository<PartyStatus>();
foreach (var entity in entities)
{
var latest = repo.Reload(entity);
// remove all associations between the entity and its history items
repoCM.Delete(latest.History);
entity.History.ToList().ForEach(a => a.Party = null);
entity.History.Clear();
//delete the unit
repo.Delete(latest);
}
// commit changes
uow.Commit();
}
return (true);
}