Beispiel #1
0
        /// <summary> Retrieves the related entity of type 'MPicEntity', 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 'MPicEntity' which is related to this entity.</returns>
        public virtual MPicEntity GetSingleMpic(bool forceFetch)
        {
            if( ( !_alreadyFetchedMpic || forceFetch || _alwaysFetchMpic) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)
            {
                bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(TJadwalEntity.Relations.MPicEntityUsingCPic);

                MPicEntity newEntity = new MPicEntity();
                if(base.ParticipatesInTransaction)
                {
                    base.Transaction.Add(newEntity);
                }
                bool fetchResult = false;
                if(performLazyLoading)
                {
                    fetchResult = newEntity.FetchUsingPK(this.CPic);
                }
                if(fetchResult)
                {
                    if(base.ActiveContext!=null)
                    {
                        newEntity = (MPicEntity)base.ActiveContext.Get(newEntity);
                    }
                    this.Mpic = newEntity;
                }
                else
                {
                    if(_mpicReturnsNewIfNotFound)
                    {
                        if(performLazyLoading || (!performLazyLoading && (_mpic == null)))
                        {
                            this.Mpic = newEntity;
                        }
                    }
                    else
                    {
                        this.Mpic = null;
                    }
                }
                _alreadyFetchedMpic = fetchResult;
                if(base.ParticipatesInTransaction && !fetchResult)
                {
                    base.Transaction.Remove(newEntity);
                }
            }
            return _mpic;
        }