예제 #1
0
        /// <summary>
        /// Processes the type if it's a DTO
        /// </summary>
        /// <param name="type">The type.</param>
        private void ProcessDto(Type type)
        {
            DtoAttribute dtoAttribute = AttributeUtil.GetAttributeFrom <DtoAttribute>(type);

            if (dtoAttribute != null)
            {
                Type entityType = null;
                if (dtoAttribute.EntityType != null)
                {
                    entityType = dtoAttribute.EntityType;
                }
                else
                {
                    string entityName = dtoAttribute.EntityName;
                    if (string.IsNullOrEmpty(entityName))
                    {
                        entityName = this.GetEntityName(type.Name);
                    }
                    entityType = TypesManager.ResolveType(entityName);
                    if (entityType == null)
                    {
                        if (this.typeMetatables.ContainsKey(entityName.ToLower()))
                        {
                            entityName = this.typeMetatables[entityName.ToLower()].FullName;
                            entityType = TypesManager.ResolveType(entityName);
                        }
                    }
                }
                if (entityType != null)
                {
                    IMetamodelEntity metaEntity = this.Parent.MetamodelManager.RegisterEntity(entityType, type);
                    if (this.Metatables.ContainsKey(entityType.FullName))
                    {
                        MetaPersistentType metaType = this.Metatables[entityType.FullName];
                        Dictionary <MetaColumn, MetaMember> mapColumns = new Dictionary <MetaColumn, MetaMember>();
                        foreach (MetaMember member in metaType.Members)
                        {
                            MetaPrimitiveMember primitiveMember = member as MetaPrimitiveMember;
                            if (primitiveMember != null)
                            {
                                mapColumns.Add(primitiveMember.Column, member);
                            }
                        }
                        MetaTable metaTable = metaType.Table;
                        foreach (MetaColumn metaColumn in metaTable.Columns)
                        {
                            MetaMember member = mapColumns[metaColumn];
                            metaEntity.AddField(member.Name, metaColumn.IsPrimaryKey, !metaColumn.IsPrimaryKey);
                        }
                    }
                }
            }
        }
예제 #2
0
        public void ProcessDynamicDto(Type dtoType, Type entityType)
        {
            IMetamodelEntity metaEntity = this.Parent.MetamodelManager.RegisterEntity(entityType, dtoType);

            if (this.Metatables.ContainsKey(entityType.FullName))
            {
                MetaPersistentType metaType = this.Metatables[entityType.FullName];
                Dictionary <MetaColumn, MetaMember> mapColumns = new Dictionary <MetaColumn, MetaMember>();
                foreach (MetaMember member in metaType.Members)
                {
                    MetaPrimitiveMember primitiveMember = member as MetaPrimitiveMember;
                    if (primitiveMember != null)
                    {
                        mapColumns.Add(primitiveMember.Column, member);
                    }
                }
                MetaTable metaTable = metaType.Table;
                foreach (MetaColumn metaColumn in metaTable.Columns)
                {
                    MetaMember member = mapColumns[metaColumn];
                    metaEntity.AddField(member.Name, metaColumn.IsPrimaryKey, !metaColumn.IsPrimaryKey);
                }
            }
        }