/// <summary> Removes the sync logic for member _region</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 DesetupSyncRegion(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _region, new PropertyChangedEventHandler( OnRegionPropertyChanged ), "Region", NW26.RelationClasses.StaticTerritoriesRelations.RegionEntityUsingRegionIdStatic, true, signalRelatedEntity, "Territories", resetFKFields, new int[] { (int)TerritoriesFieldIndex.RegionId } );
			_region = null;
		}
		/// <summary> setups the sync logic for member _region</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncRegion(IEntityCore relatedEntity)
		{
			if(_region!=relatedEntity)
			{
				DesetupSyncRegion(true, true);
				_region = (RegionEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _region, new PropertyChangedEventHandler( OnRegionPropertyChanged ), "Region", NW26.RelationClasses.StaticTerritoriesRelations.RegionEntityUsingRegionIdStatic, true, new string[] {  } );
			}
		}
		protected TerritoriesEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			if(SerializationHelper.Optimization != SerializationOptimization.Fast) 
			{
				_employeeTerritories = (EntityCollection<EmployeeTerritoriesEntity>)info.GetValue("_employeeTerritories", typeof(EntityCollection<EmployeeTerritoriesEntity>));
				_region = (RegionEntity)info.GetValue("_region", typeof(RegionEntity));
				if(_region!=null)
				{
					_region.AfterSave+=new EventHandler(OnEntityAfterSave);
				}
				this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance());
			}
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
			
		}