Hi,
On page 415 of Developers Guide, there are some sample codes for an approach for soft delete, but seems like they are a bit dated (for classic DevForce perhaps).
Not sure if my event handler OnEntityManagerFetched works, but not sure if my OnEntityManagerFetching below matches what the old example is doing?
private static EntityManager m_EntityManager = DomainModelEntityManager.DefaultManager;
// constructor
public ConcreteEntity()
{
InitializeEm();
}
private void InitializeEm()
{
m_EntityManager.Fetching += new EventHandler<EntityFetchingEventArgs>(OnEntityManagerFetching);
m_EntityManager.Fetched += new EventHandler<EntityFetchedEventArgs>(OnEntityManagerFetched);
}
private static void OnEntityManagerFetching(object sender, EntityFetchingEventArgs e)
{
IEntityQuery q = e.Query;
if (q.QueryableType == typeof(ConcreteEntity))
{
DomainModel.DomainModelEntityManager dm = new DomainModelEntityManager();
EntityQuery<ConcreteEntity> eq = dm.ConcreteEntities.Where(ce => ce.Status == (int)BaseEntity.EntityStatus.Active);
QueryCache qc = new QueryCache();
qc.Add(eq);
q.AddToQueryCache(qc);
}
}
private static void OnEntityManagerFetched(object sender, EntityFetchedEventArgs e)
{
List<Entity> removeList = new List<Entity>();
foreach (Entity ent in e.Result)
{
BaseEntity baseEnt = ent as BaseEntity; // BaseEntity is a base class for ConcreteEntity
if (baseEnt != null)
{
if (baseEnt.GetEntityStatus() != BaseEntity.EntityStatus.Active)
{
removeList.Add(ent);
}
}
}
m_EntityManager.RemoveEntities<Entity>(removeList, false);
}
Thanks in advance
-Sebastian