public static void DeleteEntireLibrary(int id, bool fullDelete)
        {
            LibraryEntity le = new LibraryEntity(id);
            if (le.IsNew)
                return;

            foreach (PolicyDocumentEntity pde in le.PolicyDocument)
            {
                DeletePolicyDoc(pde);
            }

            foreach (PolicyEntity pe in le.Policy)
            {
                DeletePolicyFromLib(pe.Id);
            }

            if (fullDelete)
            {
                foreach (QueryEntity qe in le.Query)
                {
                    testController.DeleteQuery(qe.Id);
                }

                le.Delete();
            }
        }
 /// <summary> setups the sync logic for member _library</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncLibrary(IEntity relatedEntity)
 {
     if(_library!=relatedEntity)
     {
         DesetupSyncLibrary(true, true);
         _library = (LibraryEntity)relatedEntity;
         base.PerformSetupSyncRelatedEntity( _library, new PropertyChangedEventHandler( OnLibraryPropertyChanged ), "Library", PolicyEntity.Relations.LibraryEntityUsingLibraryId, true, ref _alreadyFetchedLibrary, new string[] {  } );
     }
 }
        /// <summary> Initializes the class members</summary>
        private void InitClassMembers()
        {
            _policyLink = new policyDB.CollectionClasses.PolicyLinkCollection(new PolicyLinkEntityFactory());
            _policyLink.SetContainingEntityInfo(this, "Policy");
            _alwaysFetchPolicyLink = false;
            _alreadyFetchedPolicyLink = false;
            _rule = new policyDB.CollectionClasses.RuleCollection(new RuleEntityFactory());
            _rule.SetContainingEntityInfo(this, "Policy");
            _alwaysFetchRule = false;
            _alreadyFetchedRule = false;
            _decisionNodeCollectionViaRule = new policyDB.CollectionClasses.DecisionNodeCollection(new DecisionNodeEntityFactory());
            _alwaysFetchDecisionNodeCollectionViaRule = false;
            _alreadyFetchedDecisionNodeCollectionViaRule = false;
            _effectCollectionViaRule = new policyDB.CollectionClasses.EffectCollection(new EffectEntityFactory());
            _alwaysFetchEffectCollectionViaRule = false;
            _alreadyFetchedEffectCollectionViaRule = false;
            _policyLinkCollectionViaPolicyLink = new policyDB.CollectionClasses.PolicyLinkCollection(new PolicyLinkEntityFactory());
            _alwaysFetchPolicyLinkCollectionViaPolicyLink = false;
            _alreadyFetchedPolicyLinkCollectionViaPolicyLink = false;
            _combineMode = null;
            _combineModeReturnsNewIfNotFound = true;
            _alwaysFetchCombineMode = false;
            _alreadyFetchedCombineMode = false;
            _library = null;
            _libraryReturnsNewIfNotFound = true;
            _alwaysFetchLibrary = false;
            _alreadyFetchedLibrary = false;
            _target = null;
            _targetReturnsNewIfNotFound = true;
            _alwaysFetchTarget = false;
            _alreadyFetchedTarget = false;

            PerformDependencyInjection();

            // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
            // __LLBLGENPRO_USER_CODE_REGION_END
            OnInitClassMembersComplete();
        }
 /// <summary> Removes the sync logic for member _library</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncLibrary(bool signalRelatedEntity, bool resetFKFields)
 {
     base.PerformDesetupSyncRelatedEntity( _library, new PropertyChangedEventHandler( OnLibraryPropertyChanged ), "Library", PolicyEntity.Relations.LibraryEntityUsingLibraryId, true, signalRelatedEntity, "Policy", resetFKFields, new int[] { (int)PolicyFieldIndex.LibraryId } );
     _library = null;
 }
        /// <summary> Retrieves the related entity of type 'LibraryEntity', using a relation of type 'n:1'</summary>
        /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
        /// <returns>A fetched entity of type 'LibraryEntity' which is related to this entity.</returns>
        public virtual LibraryEntity GetSingleLibrary(bool forceFetch)
        {
            if( ( !_alreadyFetchedLibrary || forceFetch || _alwaysFetchLibrary) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)
            {
                bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(PolicyEntity.Relations.LibraryEntityUsingLibraryId);

                LibraryEntity newEntity = new LibraryEntity();
                if(base.ParticipatesInTransaction)
                {
                    base.Transaction.Add(newEntity);
                }
                bool fetchResult = false;
                if(performLazyLoading)
                {
                    fetchResult = newEntity.FetchUsingPK(this.LibraryId);
                }
                if(fetchResult)
                {
                    if(base.ActiveContext!=null)
                    {
                        newEntity = (LibraryEntity)base.ActiveContext.Get(newEntity);
                    }
                    this.Library = newEntity;
                }
                else
                {
                    if(_libraryReturnsNewIfNotFound)
                    {
                        if(performLazyLoading || (!performLazyLoading && (_library == null)))
                        {
                            this.Library = newEntity;
                        }
                    }
                    else
                    {
                        this.Library = null;
                    }
                }
                _alreadyFetchedLibrary = fetchResult;
                if(base.ParticipatesInTransaction && !fetchResult)
                {
                    base.Transaction.Remove(newEntity);
                }
            }
            return _library;
        }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected PolicyEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _policyLink = (policyDB.CollectionClasses.PolicyLinkCollection)info.GetValue("_policyLink", typeof(policyDB.CollectionClasses.PolicyLinkCollection));
            _alwaysFetchPolicyLink = info.GetBoolean("_alwaysFetchPolicyLink");
            _alreadyFetchedPolicyLink = info.GetBoolean("_alreadyFetchedPolicyLink");
            _rule = (policyDB.CollectionClasses.RuleCollection)info.GetValue("_rule", typeof(policyDB.CollectionClasses.RuleCollection));
            _alwaysFetchRule = info.GetBoolean("_alwaysFetchRule");
            _alreadyFetchedRule = info.GetBoolean("_alreadyFetchedRule");
            _decisionNodeCollectionViaRule = (policyDB.CollectionClasses.DecisionNodeCollection)info.GetValue("_decisionNodeCollectionViaRule", typeof(policyDB.CollectionClasses.DecisionNodeCollection));
            _alwaysFetchDecisionNodeCollectionViaRule = info.GetBoolean("_alwaysFetchDecisionNodeCollectionViaRule");
            _alreadyFetchedDecisionNodeCollectionViaRule = info.GetBoolean("_alreadyFetchedDecisionNodeCollectionViaRule");
            _effectCollectionViaRule = (policyDB.CollectionClasses.EffectCollection)info.GetValue("_effectCollectionViaRule", typeof(policyDB.CollectionClasses.EffectCollection));
            _alwaysFetchEffectCollectionViaRule = info.GetBoolean("_alwaysFetchEffectCollectionViaRule");
            _alreadyFetchedEffectCollectionViaRule = info.GetBoolean("_alreadyFetchedEffectCollectionViaRule");
            _policyLinkCollectionViaPolicyLink = (policyDB.CollectionClasses.PolicyLinkCollection)info.GetValue("_policyLinkCollectionViaPolicyLink", typeof(policyDB.CollectionClasses.PolicyLinkCollection));
            _alwaysFetchPolicyLinkCollectionViaPolicyLink = info.GetBoolean("_alwaysFetchPolicyLinkCollectionViaPolicyLink");
            _alreadyFetchedPolicyLinkCollectionViaPolicyLink = info.GetBoolean("_alreadyFetchedPolicyLinkCollectionViaPolicyLink");
            _combineMode = (CombineModeEntity)info.GetValue("_combineMode", typeof(CombineModeEntity));
            if(_combineMode!=null)
            {
                _combineMode.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _combineModeReturnsNewIfNotFound = info.GetBoolean("_combineModeReturnsNewIfNotFound");
            _alwaysFetchCombineMode = info.GetBoolean("_alwaysFetchCombineMode");
            _alreadyFetchedCombineMode = info.GetBoolean("_alreadyFetchedCombineMode");
            _library = (LibraryEntity)info.GetValue("_library", typeof(LibraryEntity));
            if(_library!=null)
            {
                _library.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _libraryReturnsNewIfNotFound = info.GetBoolean("_libraryReturnsNewIfNotFound");
            _alwaysFetchLibrary = info.GetBoolean("_alwaysFetchLibrary");
            _alreadyFetchedLibrary = info.GetBoolean("_alreadyFetchedLibrary");
            _target = (TargetEntity)info.GetValue("_target", typeof(TargetEntity));
            if(_target!=null)
            {
                _target.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _targetReturnsNewIfNotFound = info.GetBoolean("_targetReturnsNewIfNotFound");
            _alwaysFetchTarget = info.GetBoolean("_alwaysFetchTarget");
            _alreadyFetchedTarget = info.GetBoolean("_alreadyFetchedTarget");

            base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());

            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected QueryEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _queryValue = (policyDB.CollectionClasses.QueryValueCollection)info.GetValue("_queryValue", typeof(policyDB.CollectionClasses.QueryValueCollection));
            _alwaysFetchQueryValue = info.GetBoolean("_alwaysFetchQueryValue");
            _alreadyFetchedQueryValue = info.GetBoolean("_alreadyFetchedQueryValue");
            _attributeCollectionViaQueryValue = (policyDB.CollectionClasses.AttributeCollection)info.GetValue("_attributeCollectionViaQueryValue", typeof(policyDB.CollectionClasses.AttributeCollection));
            _alwaysFetchAttributeCollectionViaQueryValue = info.GetBoolean("_alwaysFetchAttributeCollectionViaQueryValue");
            _alreadyFetchedAttributeCollectionViaQueryValue = info.GetBoolean("_alreadyFetchedAttributeCollectionViaQueryValue");
            _library = (LibraryEntity)info.GetValue("_library", typeof(LibraryEntity));
            if(_library!=null)
            {
                _library.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _libraryReturnsNewIfNotFound = info.GetBoolean("_libraryReturnsNewIfNotFound");
            _alwaysFetchLibrary = info.GetBoolean("_alwaysFetchLibrary");
            _alreadyFetchedLibrary = info.GetBoolean("_alreadyFetchedLibrary");

            base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());

            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
        /// <summary> Initializes the class members</summary>
        private void InitClassMembers()
        {
            _queryValue = new policyDB.CollectionClasses.QueryValueCollection(new QueryValueEntityFactory());
            _queryValue.SetContainingEntityInfo(this, "Query");
            _alwaysFetchQueryValue = false;
            _alreadyFetchedQueryValue = false;
            _attributeCollectionViaQueryValue = new policyDB.CollectionClasses.AttributeCollection(new AttributeEntityFactory());
            _alwaysFetchAttributeCollectionViaQueryValue = false;
            _alreadyFetchedAttributeCollectionViaQueryValue = false;
            _library = null;
            _libraryReturnsNewIfNotFound = true;
            _alwaysFetchLibrary = false;
            _alreadyFetchedLibrary = false;

            PerformDependencyInjection();

            // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
            // __LLBLGENPRO_USER_CODE_REGION_END
            OnInitClassMembersComplete();
        }
        /// <summary>Creates a new, empty LibraryEntity object.</summary>
        /// <returns>A new, empty LibraryEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new LibraryEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewLibrary
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }