New Posts New Posts RSS Feed: Soft Delete example in Dev Guide
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Soft Delete example in Dev Guide

 Post Reply Post Reply
Author
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Topic: Soft Delete example in Dev Guide
    Posted: 26-Sep-2008 at 8:03am
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
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2008 at 8:50am
There is a problem with the pm_Fetching code in the documentation for DevForce classic:
 
Here is the problematic code from one customer's implementation:
 

private static void pm_Fetching(object sender, EntityFetchingEventArgs e)

      {

          IdeaBlade.Persistence.EntityQuery q = (e.Query as IdeaBlade.Persistence.EntityQuery);

          

          if (q.EntityType is ActiveEntity)

              q.AddClause("Deleted", EntityQueryOp.EQ, false); // '1' == true

      }

 
Here was my suggestion that fixed the customer's code:
 

void mPM_Fetching(object sender, EntityFetchingEventArgs e) {

      IdeaBlade.Persistence.EntityQuery q = (e.Query as IdeaBlade.Persistence.EntityQuery);

    

      if (q.EntityType.IsSubclassOf(typeof(ActiveEntity))) {

        q.AddClause("DeleteFlag", EntityQueryOp.EQ, false); // '1' == true;

      }

    }

 

 

 

Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2008 at 9:10am
So the equivalent implementation for DevForce EF still references IdeaBlade.Persistence.dll, am I right?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2008 at 9:28am
My example is for DevForce Classic only.  The post has two primary purposes:
 
a.  Confirm that the documentation (with the exception of the pm_Fetching event) is up to date:
 
b.  Helps DevForce Classic developers who are having coding problems with the pm_Fetching event.
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2008 at 4:18pm
And is your mPM_Fetching example applicable to DevForce EF? If not, what is the equivalent?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 03-Oct-2008 at 8:44am
There is an oustanding feature request to provide a Soft Delete example for the DevForce EF Developer's Guide, but I am not sure when we will be able to get to this.
 
If you are trying to implement this yourself right now, do you have any outstanding issues or problems that you would like to share with us? 
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 03-Oct-2008 at 2:46pm
Yes, in fact I have implemented something, I'll post a reply on Sunday ;-)
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 05-Oct-2008 at 3:52pm

WRT my above codes, the OnEntityManagerFetched seems to be ok but I could not trust my implementation of OnEntityManagerFetching works. So in addition to these 2, I implement the partial AfterGets methods individually as well, for example:

        /// <summary>
        /// Implements AfterGetRelGroupsChildren to filters out inactive entities
        /// </summary>
        /// <param name="args">The source entities</param>
        partial void AfterGetRelGroupsChildren(global::IdeaBlade.EntityModel.v4.GetterArgs<global::IdeaBlade.EntityModel.v4.RelatedEntityList<RelGroup>> args)
        {
            if (args != null && args.Value != null)
            {
                // BaseEntity.IsActive is a generic delegate predicate
                List<RelGroup> filteredList = args.Value.Where<RelGroup>(BaseEntity.IsActive<RelGroup>).ToList<RelGroup>();
                ListEntityReference<RelGroup> refList = args.Value.ListReference;
                IdeaBlade.EntityModel.v4.RelatedEntityList<RelGroup> newRelatedList = new RelatedEntityList<RelGroup>(filteredList, refList);
                args.Value = newRelatedList;
            }
        }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down