示例#1
0
        /// <summary>
        /// Lazy load a property (HasMany).
        /// </summary>
        /// <typeparam name="TPropertyClass">The type of the property class.</typeparam>
        /// <param name="attr">The attr.</param>
        /// <returns></returns>
        /// <exception cref="AttributeNotFoundException"></exception>
        private List <TPropertyClass> LazyLoadMany <TPropertyClass>(HasManyAttribute attr)
            where TPropertyClass : ActiveRecordBase
        {
            ActiveRecordAttribute attribute = ActiveRecordMaster.GetAttribute(this.GetType());

            if (attribute == null)
            {
                throw new AttributeNotFoundException();
            }

            try
            {
                PrimaryKeyAttribute pk = ActiveRecordMaster.GetPrimaryKey(this.GetType());

                if (pk == null)
                {
                    return(null);
                }

                Criteria criteria = Criteria.For <TPropertyClass>();
                criteria.SQLString = ActiveRecordMaster.MakeHasManySelect(this.GetType(), attr.CurrentPropertyInfo.Name);

                criteria.AddParameter("@CODE", pk.CurrentPropertyInfo.Name, pk.CurrentPropertyInfo.GetValue(this, null));

                return(ActiveRecordMaster.ExecuteQueryCriteria <TPropertyClass>(criteria));
            }
            catch (Exception ex)
            {
                LogManager.Log("Monty.ActiveRecord", LogCategory.Error, String.Format("Error when tries to execute ActiveRecordBase.FindByForeignKey(attr: [{0}])", attr), ex);
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Checks the type atrribute.
        /// </summary>
        /// <param name="type">The type.</param>
        public static void CheckTypeAtrribute(Type type)
        {
            ActiveRecordAttribute attribute = ActiveRecordMaster.GetAttribute(type);
            PrimaryKeyAttribute   pk        = ActiveRecordMaster.GetPrimaryKey(type);

            CheckTypeAtrribute(type, ref attribute, ref pk);
        }
示例#3
0
        /// <summary>
        /// Deletes this item
        /// </summary>
        /// <returns></returns>
        /// <exception cref="AttributeNotFoundException">Class attribute parameter 'Mutable' must be seted to 'true'</exception>
        public virtual bool Delete()
        {
            ActiveRecordAttribute attribute = null;

            CheckTypeAtrribute(this.GetType(), ref attribute);

            if (!attribute.Mutable)
            {
                throw new AttributeNotFoundException("Class attribute parameter 'Mutable' must be seted to 'true'");
            }

            if (!ActiveRecordMaster.Delete(this.GetType(), this))
            {
                return(false);
            }

            //Cascade Delete
            if (ActiveRecordMaster.HasJoinedBase(this.GetType()) != null)
            {
                if (ActiveRecordMaster.GetAttribute(this.GetType().BaseType) != null)
                {
                    if (!ActiveRecordMaster.Delete(this.GetType().BaseType, this))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }