Example #1
0
 public TemplateContainer Convert(MetaModel metamodel)
 {
     this.model = metamodel;
     TemplateContainer root = new TemplateContainer();
     root.AddAttribute("Test", "OK");
     this.BuildDomains(root.AddChild("Domains"));
     this.BuildColumns(root.AddChild("Columns"));
     this.BuildTables(root.AddChild("Tables"));
     return root;
 }
Example #2
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;
 }