Esempio n. 1
0
 public void WriteForeignKeyProperty(TypeFk fk)         // used by razor templates
 {
     if (fk.CollectionProperty.GetGetMethod().IsVirtual)
     {
         Write(Render <TypeFk>("ForeignKeyProperty.tmpl", new { Model = fk }));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Get the PropertyInfo that represents the child collection for the specified
        /// TypeFk
        /// </summary>
        /// <param name="typeFk"></param>
        /// <returns></returns>
        protected internal PropertyInfo GetChildCollectionDaoPropertyForTypeFk(TypeFk typeFk)
        {
            Type         primaryDaoType    = GetDaoType(typeFk.PrimaryKeyType);
            Type         foreignKeyDaoType = GetDaoType(typeFk.ForeignKeyType);
            string       propertyName      = string.Format("{0}By{1}", foreignKeyDaoType.Name.Pluralize(), typeFk.ForeignKeyProperty.Name);
            PropertyInfo childCollectionPropertyForTypeFk = primaryDaoType.GetProperty(propertyName);

            return(childCollectionPropertyForTypeFk);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the PropertyInfo that represents the parent object instance for the specified
        /// TypeFk
        /// </summary>
        /// <param name="typeFk"></param>
        /// <returns></returns>
        protected internal PropertyInfo GetParentDaoPropertyOfChildForTypeFk(TypeFk typeFk)
        {
            // ParentType.Name Of ForeignKeyProperty.Name
            Type         foreignKeyDaoType = GetDaoType(typeFk.ForeignKeyType);
            string       propertyName      = string.Format("{0}Of{1}", foreignKeyDaoType.Name, typeFk.ForeignKeyProperty.Name);
            PropertyInfo parentPropertyOfChildForTypeFk = foreignKeyDaoType.GetProperty(propertyName);

            return(parentPropertyOfChildForTypeFk);
        }
Esempio n. 4
0
        public void WriteChildPrimaryKeyProperty(TypeFk fk)
        {
            MethodInfo method = fk.ChildParentProperty.GetGetMethod();

            if (method != null && method.IsVirtual)
            {
                Write(Render <TypeFk>("ChildPrimaryKeyProperty.tmpl", new { Model = fk }));
            }
        }
Esempio n. 5
0
        public override bool Equals(object obj)
        {
            TypeFk compareTo = obj as TypeFk;

            if (compareTo != null)
            {
                return(PrimaryKeyType.Equals(compareTo.PrimaryKeyType) && ForeignKeyType.Equals(compareTo.ForeignKeyType));
            }
            return(base.Equals(obj));
        }
Esempio n. 6
0
        public IEnumerable <TChildType> ForeignKeyCollectionLoader <TParentType, TChildType>(object poco) where TChildType : new() // this is used by generated code; JIT compiler can't tell
        {
            // get all the child types where the foreign key property value equals the parent id
            TypeFk fkDescriptor = TypeSchema.ForeignKeys.FirstOrDefault(tfk => tfk.PrimaryKeyType == typeof(TParentType) && tfk.ForeignKeyType == typeof(TChildType));

            if (fkDescriptor != null)
            {
                return(LoadForeignKeyCollection <TChildType>(poco, fkDescriptor));
            }
            return(new List <TChildType>());
        }
Esempio n. 7
0
        private IEnumerable <TChildType> LoadForeignKeyCollection <TChildType>(object poco, TypeFk fkDescriptor) where TChildType : new()
        {
            List <TChildType> results        = new List <TChildType>();
            string            foreignKeyName = fkDescriptor.ForeignKeyProperty.Name;
            long parentId = GetIdValue(poco).Value;

            if (parentId <= 0)
            {
                Args.Throw <InvalidOperationException>("IdValue not found for specified parent instance: {0}",
                                                       poco.PropertiesToString());
            }
            QueryFilter filter       = Bam.Net.Data.Query.Where(foreignKeyName) == parentId;
            Type        childDaoType = GetDaoType(typeof(TChildType));
            MethodInfo  whereMethod  = childDaoType.GetMethod("Where", new Type[] { typeof(QueryFilter), typeof(Database) });
            IEnumerable daoResults   = (IEnumerable)whereMethod.Invoke(null, new object[] { filter, Database });

            foreach (object dao in daoResults)
            {
                Type       wrapperType = GetWrapperType <TChildType>();
                TChildType value       = wrapperType.Construct <TChildType>(this);
                value.CopyProperties(dao);
                results.Add(value);
            }

            return(results);
        }
Esempio n. 8
0
        public IEnumerable <TChildType> ForeignKeyCollectionLoader <TChildType>(object poco) where TChildType : new() // this is used by generated code; JIT compiler can't tell
        {
            TypeFk fkDescriptor = TypeSchema.ForeignKeys.FirstOrDefault(tfk => tfk.ForeignKeyType == typeof(TChildType));

            return(LoadForeignKeyCollection <TChildType>(poco, fkDescriptor));
        }