Exemplo n.º 1
0
        /// <summary>
        /// Lazy load a property (BelongsTo).
        /// </summary>
        /// <typeparam name="TPropertyClass">The type of the property class.</typeparam>
        /// <param name="property">The property.</param>
        /// <returns></returns>
        protected TPropertyClass LazyLoad <TPropertyClass>(string property)
            where TPropertyClass : ActiveRecordBase
        {
            if (!this.LazyObjects.ContainsKey(property))
            {
                return(null);
            }

            BelongsToAttribute attr = ActiveRecordMaster.GetBelongsTo(this.GetType(), property);

            if (this.LazyObjects[property] == null || String.IsNullOrEmpty(this.LazyObjects[property].ToString()))
            {
                return(null);
            }

            TPropertyClass item = ActiveRecordBase <TPropertyClass> .Find(this.LazyObjects[property]);

            if (attr.NotFoundBehaviour == NotFoundBehaviour.Exception && item == null)
            {
                throw new ObjectNotFoundException(typeof(TPropertyClass).Name);
            }

            return(item);
        }