/// <summary>
        /// Maintains the references of the provided entity by deleting the obsolete references (those in the data store but no longer active on one of the properties)
        /// and persisting the new references into the data store.
        /// </summary>
        /// <param name="entity">The entity to maintain the references for.</param>
        public virtual void MaintainReferences(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Maintaining the references for the provided entity.", LogLevel.Debug))
            {
                EntityReferenceCollection updateList = new EntityReferenceCollection();
                EntityReferenceCollection deleteList = new EntityReferenceCollection();

                // Get the current/actives references
                foreach (EntityReference reference in GetActiveReferences(entity))
                {
                    updateList.Add(reference);
                }

                // Get the obsolete references
                foreach (EntityReference reference in GetObsoleteReferences(entity, updateList.GetEntityIDs(entity.ID)))
                {
                    deleteList.Add(reference);
                }

                // Delete the obsolete references
                LogWriter.Debug("References to delete: " + deleteList.Count);

                DeleteObsoleteReferences(deleteList);


                // Update/save the current references
                LogWriter.Debug("References to update: " + updateList.Count);

                PersistReferences(updateList);

                Provider.Referencer.SetCountProperties(entity, false);
            }
        }
        /// <summary>
        /// Maintains the references of the provided entity by deleting the obsolete references (those in the data store but no longer active on one of the properties)
        /// and persisting the new references into the data store.
        /// </summary>
        /// <param name="entity">The entity to maintain the references for.</param>
        public virtual void MaintainReferences(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Maintaining the references for the provided entity.", LogLevel.Debug))
            {
                EntityReferenceCollection updateList = new EntityReferenceCollection();
                EntityReferenceCollection deleteList = new EntityReferenceCollection();

                // Get the current/actives references
                foreach (EntityReference reference in GetActiveReferences(entity))
                {
                    updateList.Add(reference);
                }

                // Get the obsolete references
                foreach (EntityReference reference in GetObsoleteReferences(entity, updateList.GetEntityIDs(entity.ID)))
                {
                    deleteList.Add(reference);
                }

                // Delete the obsolete references
                LogWriter.Debug("References to delete: " + deleteList.Count);

                DeleteObsoleteReferences(deleteList);

                // Update/save the current references
                LogWriter.Debug("References to update: " + updateList.Count);

                PersistReferences(updateList);

                Provider.Referencer.SetCountProperties(entity, false);
            }
        }