コード例 #1
0
        /// <summary> Retrieves the related entity of type 'DonorEntity', 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 'DonorEntity' which is related to this entity.</returns>
        public virtual DonorEntity GetSingleDonor(bool forceFetch)
        {
            if( ( !_alreadyFetchedDonor || forceFetch || _alwaysFetchDonor) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)
            {
                bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(AuctionEventDonorEntity.Relations.DonorEntityUsingDonorId);

                DonorEntity newEntity = new DonorEntity();
                if(base.ParticipatesInTransaction)
                {
                    base.Transaction.Add(newEntity);
                }
                bool fetchResult = false;
                if(performLazyLoading)
                {
                    fetchResult = newEntity.FetchUsingPK(this.DonorId);
                }
                if(fetchResult)
                {
                    if(base.ActiveContext!=null)
                    {
                        newEntity = (DonorEntity)base.ActiveContext.Get(newEntity);
                    }
                    this.Donor = newEntity;
                }
                else
                {
                    if(_donorReturnsNewIfNotFound)
                    {
                        if(performLazyLoading || (!performLazyLoading && (_donor == null)))
                        {
                            this.Donor = newEntity;
                        }
                    }
                    else
                    {
                        this.Donor = null;
                    }
                }
                _alreadyFetchedDonor = fetchResult;
                if(base.ParticipatesInTransaction && !fetchResult)
                {
                    base.Transaction.Remove(newEntity);
                }
            }
            return _donor;
        }