예제 #1
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static List <Member> GenerateMembers(Type type, Member rootMember = null, Member parentMember = null)
        {
            List <Member> members = new List <Member>();

            foreach (var cm in GenerateColumnMembers(type))
            {
                if (!cm.Skip)
                {
                    cm.Parent = parentMember;
                    cm.Root   = rootMember;
                    members.Add(cm);
                }
            }
            if (ModelCache.HasReferencedObjectMembers(type))
            {
                foreach (var rom in GenerateReferencedObjectMembers(type))
                {
                    rom.Parent = parentMember;
                    rom.Root   = rootMember;
                    members.Add(rom);
                }
            }
            if (ModelCache.HasChildCollectionMembers(type))
            {
                foreach (var ccm in GenerateChildCollectionMembers(type))
                {
                    ccm.Parent = parentMember;
                    ccm.Root   = rootMember;
                    members.Add(ccm);
                }
            }
            return(members);
        }
예제 #2
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static Boolean IsModel(Type t)
        {
            var table_attribute   = ModelCache.GetTableAttribute(t);
            var column_attributes = ModelCache.GetColumnMembers(t);

            return(table_attribute != null && column_attributes != null && column_attributes.Any());
        }
예제 #3
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static void Populate(object instance, IndexedSqlDataReader dr)
        {
            var thisType = instance.GetType();
            var members  = ModelCache.GetColumnMemberLookup(thisType);

            foreach (var col in members.Values)
            {
                col.SetValue(instance, dr.Get(col));
            }
        }
예제 #4
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static ChildCollectionMember[] GenerateChildCollectionMembers(Type type)
        {
            var list = new List <ChildCollectionMember>();

            PropertyInfo[] properties = ModelCache.GetChildCollectionMemberProperties(type);
            foreach (var prop in properties)
            {
                list.Add(new ChildCollectionMember(prop));
            }

            return(list.ToArray());
        }
예제 #5
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static ReferencedObjectMember[] GenerateReferencedObjectMembers(Type type)
        {
            var list = new List <ReferencedObjectMember>();

            PropertyInfo[] properties = ModelCache.GetReferencedObjectMemberProperties(type);
            foreach (var prop in properties)
            {
                list.Add(new ReferencedObjectMember(prop));
            }

            return(list.ToArray());
        }
예제 #6
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static ColumnMember[] GenerateColumnMembers(Type type)
        {
            PropertyInfo[] properties = ModelCache.GetColumnMemberProperties(type);
            var            members    = new List <ColumnMember>();

            foreach (var prop in properties)
            {
                members.Add(new ColumnMember(prop));
            }

            return(members.ToArray());
        }
예제 #7
0
파일: Model.cs 프로젝트: gonbike/Destrier
        static void _generateMembersImpl(Type type, List <Member> members, Member rootMember, Member parentMember = null)
        {
            foreach (var cm in GenerateColumnMembers(type))
            {
                if (!cm.Skip)
                {
                    cm.Parent = parentMember;
                    cm.Root   = rootMember;
                    members.Add(cm);
                }
            }

            if (ModelCache.HasReferencedObjectMembers(type))
            {
                foreach (var rom in GenerateReferencedObjectMembers(type))
                {
                    rom.Parent = parentMember;
                    rom.Root   = rootMember;

                    if (!rom.HasCycle)
                    {
                        members.Add(rom);
                        _generateMembersImpl(rom.Type, members, rootMember, rom);
                    }
                }
            }

            if (ModelCache.HasChildCollectionMembers(type))
            {
                foreach (var ccp in GenerateChildCollectionMembers(type))
                {
                    ccp.Parent = parentMember;
                    ccp.Root   = rootMember;

                    if (parentMember != null && parentMember is ReferencedObjectMember)
                    {
                        ccp.ParentReferencedMember.Parent = parentMember;
                    }

                    if (!ccp.HasCycle)
                    {
                        members.Add(ccp);
                        _generateMembersImpl(ccp.CollectionType, members, rootMember, ccp);
                    }
                }
            }
        }
예제 #8
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static String TableName(Type t)
        {
            var ta = ModelCache.GetTableAttribute(t);

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

            if (!String.IsNullOrEmpty(ta.TableName))
            {
                return(ta.TableName);
            }
            else
            {
                return(t.Name);
            }
        }
예제 #9
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static void CheckColumns(Type t)
        {
            if (ModelCache.GetTableAttribute(t) != null)
            {
                var databaseColumns = Schema.GetColumnsForTable(Model.TableName(t), Model.DatabaseName(t), Model.ConnectionString(t));
                var columnMembers   = Model.GenerateColumnMembers(t);

                foreach (var cm in columnMembers)
                {
                    var modelColumn = cm.ColumnAttribute;
                    if (!modelColumn.IsForReadOnly)
                    {
                        if (!databaseColumns.Any(c => c.Name.Equals(cm.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            throw new ColumnMissingException(String.Format("\'{0}\' : Column in the model doesn't map to the schema.", cm.Name));
                        }

                        var databaseColumn = databaseColumns.FirstOrDefault(c => c.Name.Equals(cm.Name, StringComparison.InvariantCultureIgnoreCase));

                        if (!modelColumn.IsPrimaryKey && databaseColumn.CanBeNull != modelColumn.CanBeNull)
                        {
                            throw new ColumnNullabilityException(String.Format("Column Nullability Mismatch : {4} DBColumn: {0} {2} ModelColumn: {1} {3}"
                                                                               , databaseColumn.Name
                                                                               , cm.Name
                                                                               , databaseColumn.CanBeNull.ToString()
                                                                               , modelColumn.CanBeNull.ToString()
                                                                               , Model.TableName(t))
                                                                 );
                        }
                    }
                }

                foreach (var column in databaseColumns)
                {
                    if (!column.IsForReadOnly)
                    {
                        if (!columnMembers.Any(c => c.Name.Equals(column.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            throw new ColumnMissingException(String.Format("\'{0}\' : Column in the schema ({1}) doesn't map to the model.", column.Name, Model.TableName(t)));
                        }
                    }
                }
            }
        }
예제 #10
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static String ConnectionString(Type t)
        {
            var ta = ModelCache.GetTableAttribute(t);

            if (ta == null)
            {
                throw new SchemaMetadataException("Base Model classes must have a 'Table' attribute specifying the relation in the database to interact with!");
            }

            if (!String.IsNullOrEmpty(ta.ConnectionName))
            {
                return(DatabaseConfigurationContext.ConnectionStrings[ta.ConnectionName]);
            }
            else if (!String.IsNullOrEmpty(DatabaseConfigurationContext.DefaultConnectionString))
            {
                return(DatabaseConfigurationContext.DefaultConnectionString);
            }
            else
            {
                throw new SchemaMetadataException("No connection string for object.");
            }
        }
예제 #11
0
파일: Model.cs 프로젝트: gonbike/Destrier
 public static ColumnMember[] ColumnsPrimaryKey(Type t)
 {
     return(ModelCache.GetColumnMembers(t).Where(cm => cm.IsPrimaryKey).ToArray());
 }
예제 #12
0
파일: Model.cs 프로젝트: gonbike/Destrier
        public static String ConnectionName(Type t)
        {
            TableAttribute ta = ModelCache.GetTableAttribute(t);

            return(ta.ConnectionName ?? DatabaseConfigurationContext.DefaultConnectionName);
        }
예제 #13
0
파일: Model.cs 프로젝트: gonbike/Destrier
 public static ColumnMember ColumnMemberForPropertyName(Type type, String propertyName)
 {
     return(ModelCache.GetColumnMemberStandardizedLookup(type)[Model.StandardizeCasing(propertyName)]);
 }