Ejemplo n.º 1
0
 /// <summary>
 /// Builds this instance.
 /// </summary>
 public void Build()
 {
     foreach (MetaRelation relation in this.Relations)
     {
         MetaTable parentTable = this.GetTable(relation.ParentName);
         relation.Parent = parentTable;
         IList<MetaColumn> parentKeys = parentTable.GetPrimaryKeys();
         foreach (MetaColumn key in parentKeys)
         {
             MetaColumn column = new MetaColumn();
             if (key.Name.ToLower().StartsWith(relation.SonRelationName.ToLower()))
             {
                 column.Name = key.Name;
             }
             else
             {
                 column.Name = relation.SonRelationName + StringUtil.FirstUpper(key.Name);
             }
             column.IsIdentity = false;
             column.IsPrimaryKey = relation.IsKeyInSon;
             column.IsNullable = relation.IsNullableInSon;
             column.DataType = key.DataType;
             column.DataTypeLength = key.DataTypeLength;
             column.DataTypeDecimals = key.DataTypeDecimals;
             column.IsForeignKey = true;
             column.TargetColumn = key;
             relation.Son.AddColumn(column);
             relation.ParentColumns.Add(key);
             relation.SonColumns.Add(column);
         }
     }
     IList<MetaDomain> unusedDomains = new List<MetaDomain>();
     foreach (MetaDomain domain in this.Domains)
     {
         if (!domain.IsUsed)
         {
             unusedDomains.Add(domain);
         }
     }
     foreach (MetaDomain domain in unusedDomains)
     {
         this.domainMap.Remove(domain.Name);
         this.Domains.Remove(domain);
     }
     int i = 1;
     foreach (MetaDomain domain in this.Domains)
     {
         domain.Id = i;
         i++;
     }
     i = 1;
     foreach (MetaTable table in this.Tables)
     {
         table.Id = i;
         int j = 1;
         foreach (MetaColumn column in table.Columns)
         {
             column.TableId = table.Id;
             column.Ix = j;
             j++;
         }
         i++;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the column.
 /// </summary>
 /// <param name="column">The column.</param>
 public void AddColumn(MetaColumn column)
 {
     column.Table = this;
     this.Columns.Add(column);
     this.columnMap.Add(column.Name.ToLower(), column);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds the column.
 /// </summary>
 /// <param name="column">The column.</param>
 public void AddColumn(MetaColumn column)
 {
     column.Table = this;
     this.Columns.Add(column);
     this.columnMap.Add(column.Name.ToLower(), column);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Builds the metamodel.
 /// </summary>
 /// <returns></returns>
 public MetaModel Build()
 {
     MetaModel result = new MetaModel();
     foreach (StructureDomain domain in this.Domains)
     {
         MetaDomain metaDomain = new MetaDomain();
         metaDomain.Id = null;
         metaDomain.Name = domain.Name;
         metaDomain.IsIdentity = domain.IsIdentity;
         metaDomain.DataType = domain.DataType;
         metaDomain.DataTypeLength = domain.DataTypeLength;
         metaDomain.DataTypeDecimals = domain.DataTypeDecimals;
         metaDomain.IsUsed = false;
         result.AddDomain(metaDomain);
     }
     foreach (StructureEntity entity in this.Entities)
     {
         MetaTable table = new MetaTable();
         table.Id = null;
         table.Name = entity.Name;
         table.PhysicalName = StringUtil.Camelize(table.Name);
         table.LogicalName = StringUtil.Pascalize(table.Name);
         result.AddTable(table);
         foreach (StructureProperty property in entity.Properties)
         {
             if ((property.ReferenceItem == null) || (property.ReferenceItem is StructureDomain))
             {
                 MetaColumn column = new MetaColumn();
                 column.TableId = null;
                 column.Ix = null;
                 column.Name = property.Name;
                 MetaDomain metaDomain;
                 if (property.ReferenceItem == null)
                 {
                     string generatedDomainName = this.GenerateDomainName(property.DataType, property.DataTypeLength, property.DataTypeDecimals, property.IsIdentity);
                     metaDomain = result.GetDomain(generatedDomainName);
                     if (metaDomain == null)
                     {
                         metaDomain = new MetaDomain();
                         metaDomain.Id = null;
                         metaDomain.Name = generatedDomainName;
                         metaDomain.IsIdentity = property.IsIdentity;
                         metaDomain.DataType = property.DataType;
                         metaDomain.DataTypeLength = property.DataTypeLength;
                         metaDomain.DataTypeDecimals = property.DataTypeDecimals;
                         result.AddDomain(metaDomain);
                     }
                 }
                 else
                 {
                     metaDomain = result.GetDomain(property.ReferenceItem.Name);
                 }
                 metaDomain.IsUsed = true;
                 column.Domain = metaDomain;
                 column.IsIdentity = property.IsIdentity || metaDomain.IsIdentity;
                 column.IsPrimaryKey = property.IsPrimaryKey || column.IsPrimaryKey;
                 column.IsNullable = property.IsNullable && !column.IsPrimaryKey;
                 column.DataType = metaDomain.DataType;
                 column.DataTypeLength = metaDomain.DataTypeLength;
                 column.DataTypeDecimals = metaDomain.DataTypeLength;
                 column.IsForeignKey = false;
                 table.AddColumn(column);
             }
             else
             {
                 MetaRelation relation = new MetaRelation();
                 relation.ParentName = property.ReferenceItem.Name;
                 relation.SonRelationName = property.Name;
                 relation.Son = table;
                 relation.IsKeyInSon = property.IsPrimaryKey;
                 relation.IsNullableInSon = property.IsNullable;
                 result.Relations.Add(relation);
             }
         }
     }
     result.Build();
     return result;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Builds this instance.
        /// </summary>
        public void Build()
        {
            foreach (MetaRelation relation in this.Relations)
            {
                MetaTable parentTable = this.GetTable(relation.ParentName);
                relation.Parent = parentTable;
                IList <MetaColumn> parentKeys = parentTable.GetPrimaryKeys();
                foreach (MetaColumn key in parentKeys)
                {
                    MetaColumn column = new MetaColumn();
                    if (key.Name.ToLower().StartsWith(relation.SonRelationName.ToLower()))
                    {
                        column.Name = key.Name;
                    }
                    else
                    {
                        column.Name = relation.SonRelationName + StringUtil.FirstUpper(key.Name);
                    }
                    column.IsIdentity       = false;
                    column.IsPrimaryKey     = relation.IsKeyInSon;
                    column.IsNullable       = relation.IsNullableInSon;
                    column.DataType         = key.DataType;
                    column.DataTypeLength   = key.DataTypeLength;
                    column.DataTypeDecimals = key.DataTypeDecimals;
                    column.IsForeignKey     = true;
                    column.TargetColumn     = key;
                    relation.Son.AddColumn(column);
                    relation.ParentColumns.Add(key);
                    relation.SonColumns.Add(column);
                }
            }
            IList <MetaDomain> unusedDomains = new List <MetaDomain>();

            foreach (MetaDomain domain in this.Domains)
            {
                if (!domain.IsUsed)
                {
                    unusedDomains.Add(domain);
                }
            }
            foreach (MetaDomain domain in unusedDomains)
            {
                this.domainMap.Remove(domain.Name);
                this.Domains.Remove(domain);
            }
            int i = 1;

            foreach (MetaDomain domain in this.Domains)
            {
                domain.Id = i;
                i++;
            }
            i = 1;
            foreach (MetaTable table in this.Tables)
            {
                table.Id = i;
                int j = 1;
                foreach (MetaColumn column in table.Columns)
                {
                    column.TableId = table.Id;
                    column.Ix      = j;
                    j++;
                }
                i++;
            }
        }