public void CreateUDSDocumentsTable(SmoContext ctx)
        {
            Table tb = new Table(ctx.DbInstace, UDSDocumentsTableName, _dbSchema);

            Column col = new Column(tb, UDSDocumentsPK, DataType.UniqueIdentifier)
            {
                Nullable = false
            };

            tb.Columns.Add(col);

            col = new Column(tb, UDSFK, DataType.UniqueIdentifier)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSDocumentsFK, DataType.UniqueIdentifier)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSDocumentsDocumentNameField, DataType.NVarChar(256))
            {
                Nullable = true
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSDocumentsDocumentTypeField, DataType.SmallInt)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSDocumentsDocumentLabelField, DataType.NVarChar(256))
            {
                Nullable = true
            };
            tb.Columns.Add(col);

            AddDateTimeOffsetField(UDSRegistrationDateField, tb);

            tb.ValidateSchema();
            tb.Create();

            tb.AddPrimaryKey(UDSDocumentsPK);
            tb.AddForeignKey(UDSFK, UDSTableName, _dbSchema, UDSPK);
            tb.AddIndex(UDSFK);
            tb.AddClusterIndex(UDSRegistrationDateField);
        }
        public void CreateUDSTable(SmoContext ctx)
        {
            Table tb = new Table(ctx.DbInstace, _tableName, _dbSchema);

            Column col = new Column(tb, UDSPK, DataType.UniqueIdentifier)
            {
                Nullable = false
            };

            tb.Columns.Add(col);

            //colonne dei metadati
            if (_uds.Model.Metadata != null && _uds.Model.Metadata.Length > 0)
            {
                foreach (Section section in _uds.Model.Metadata.Where(f => f.Items != null))
                {
                    foreach (FieldBaseType field in section.Items)
                    {
                        AddField(field, tb);
                    }
                }
            }

            col = new Column(tb, UDSRepositoryFK, DataType.UniqueIdentifier)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            //colonne di default
            AddDateTimeOffsetField(UDSRegistrationDateField, tb);

            col = new Column(tb, UDSRegistrationUserField, DataType.NVarChar(256))
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            AddDateTimeOffsetField(UDSLastChangedDateField, tb, true);

            col = new Column(tb, UDSLastChangedUserField, DataType.NVarChar(256))
            {
                Nullable = true
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSYearField, DataType.SmallInt)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSNumberField, DataType.Int)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSSubjectField, DataType.NVarChar(4000))
            {
                Nullable = true
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSIdCategoryFK, DataType.SmallInt)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSStatusField, DataType.SmallInt)
            {
                Nullable = false
            };
            col.AddDefaultConstraint().Text = "1"; // Active
            tb.Columns.Add(col);

            col = new Column(tb, UDSCancelMotivationField, DataType.NVarChar(1024))
            {
                Nullable = true
            };
            tb.Columns.Add(col);

            col = new Column(tb, UDSTimestampField, DataType.Timestamp)
            {
                Nullable = false
            };
            tb.Columns.Add(col);

            //Create the table on the instance of SQL Server.
            tb.ValidateSchema();
            tb.Create();

            tb.AddPrimaryKey(UDSPK);
            tb.AddForeignKey(UDSIdCategoryFK, DSWCategoryTableName, "dbo", DSWIdCategoryPK);
            tb.AddForeignKey(UDSRepositoryFK, UDSRepositoriesTableName, _dbSchema, UDSRepositoryFK);
            tb.AddClusterIndex(UDSRegistrationDateField);
            tb.AddIndex(new List <string>()
            {
                UDSYearField, UDSNumberField
            });
        }