Esempio n. 1
0
        private static string GeneratePropertyAttribute(TableColumnDefinition column)
        {
            StringBuilder attrBuilder = new StringBuilder();

            attrBuilder.Append("ActiveColumn(\"" + column.Name + "\", DbType." + column.DbType + ", ");
            AddColumnPropertyValues(attrBuilder, column);

            attrBuilder.Append(")");
            return(attrBuilder.ToString());
        }
Esempio n. 2
0
        private void SetAuditFields(TableColumnDefinition column)
        {
            AuditMappingElement config = configuration.AuditMapping;

            bool created  = (string.Compare(column.Name, config.CreatedOnColumn, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(column.Name, config.CreatedbyColumn, StringComparison.OrdinalIgnoreCase) == 0);
            bool modified = (string.Compare(column.Name, config.ModifiedByColumn, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(column.Name, config.ModifiedOnColumn, StringComparison.OrdinalIgnoreCase) == 0);
            bool user     = (string.Compare(column.Name, config.CreatedbyColumn, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(column.Name, config.ModifiedByColumn, StringComparison.OrdinalIgnoreCase) == 0);
            bool date     = (string.Compare(column.Name, config.CreatedOnColumn, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(column.Name, config.ModifiedOnColumn, StringComparison.OrdinalIgnoreCase) == 0);
            bool deleted  = (string.Compare(column.Name, config.DeletedColumn, StringComparison.OrdinalIgnoreCase) == 0);

            column.AuditField = new AuditField(user, date, modified, created, deleted);
        }
Esempio n. 3
0
        public string GenerateProcedureProperties(ProcedureDefinition procedure)
        {
            StringBuilder builder          = new StringBuilder();
            string        templateProperty = Templates.ProcedureProperty;

            foreach (ProcedureParameterDefinition parameter in procedure.Parameters)
            {
                builder.AppendLine();

                string propertyName   = parameter.ToPascalCase(CodeFormatOptions.None);
                string xmlElementName = propertyName;

                if (parameter.Name == procedure.Name)
                {
                    propertyName += "_";
                }
                if (procedure.CharAsBooleans.ContainsKey(parameter.Name))
                {
                    builder.AppendLine(templateProperty.
                                       Replace(Tokens.SchemaAttributes, GeneratePropertyAttribute(parameter)).
                                       Replace(Tokens.XmlAttribute, xmlElementName).
                                       Replace(Tokens.DataTypeShort, TableColumnDefinition.GetDataTypeShort(DbType.Boolean, false, session.Configuration.CodeGen.UseNullableTypes)).
                                       Replace(Tokens.DataTypeLong, "CharAsBoolean").
                                       Replace("#SETOPTION#", "BooleanAsChar").
                                       Replace(Tokens.PropertyName, propertyName).
                                       Replace(Tokens.ColumnName, propertyName));
                }
                else
                {
                    builder.AppendLine(templateProperty.
                                       Replace(Tokens.SchemaAttributes, GeneratePropertyAttribute(parameter)).
                                       Replace(Tokens.XmlAttribute, xmlElementName).
                                       Replace(Tokens.DataTypeShort, parameter.GetDataTypeShort()).
                                       Replace(Tokens.DataTypeLong, parameter.GetDataTypeLong()).
                                       Replace("#SETOPTION#", string.Empty).
                                       Replace(Tokens.PropertyName, propertyName).
                                       Replace(Tokens.ColumnName, propertyName));
                }
            }

            return(builder.ToString());
        }
Esempio n. 4
0
        public void EnsureLocalizableColumns()
        {
            foreach (TableDefinition item in this)
            {
                foreach (TablesElement table in Configuration.Tables)
                {
                    if (table.Owner != item.Owner || table.Name != item.Name)
                    {
                        continue;
                    }

                    if (Compare.IsNullOrEmpty(table.LocalizationTableName))
                    {
                        continue;
                    }
                    if (Compare.IsNullOrEmpty(table.LocalizableColumns))
                    {
                        continue;
                    }

                    foreach (string columnName in table.LocalizableColumns.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        TableColumnDefinition column = item.Columns.FindColumn(columnName);
                        if (column == null)
                        {
                            continue;
                        }

                        TableColumnDefinition translatedColumn = column.LocalizationColumn = FindColumn(table.LocalizationTableSchema, table.LocalizationTableName, columnName);
                        if (translatedColumn == null)
                        {
                            continue;
                        }

                        column.IsLocalizable      = true;
                        column.LocalizationColumn = translatedColumn;
                    }
                }
            }
        }
 public string GetDataTypeLong()
 {
     return(TableColumnDefinition.GetDataTypeLong(dbType, false, configuration.CodeGen.UseNullableTypes));
 }
Esempio n. 6
0
        private static void AddColumnPropertyValues(StringBuilder attributeBuilder, TableColumnDefinition column)
        {
            bool hasProperty = false;

            if (column.IsComputed)
            {
                attributeBuilder.Append("ColumnProperties.Computed");
                hasProperty = true;
            }
            if (column.IsForeignKey)
            {
                if (hasProperty)
                {
                    attributeBuilder.Append(" | ");
                }
                attributeBuilder.Append("ColumnProperties.ForeignKey");
                hasProperty = true;
            }
            if (column.IsIdentity)
            {
                if (hasProperty)
                {
                    attributeBuilder.Append(" | ");
                }
                attributeBuilder.Append("ColumnProperties.Identity");
                hasProperty = true;
            }
            if (column.IsNullable)
            {
                if (hasProperty)
                {
                    attributeBuilder.Append(" | ");
                }
                attributeBuilder.Append("ColumnProperties.Nullable");
                hasProperty = true;
            }
            if (column.IsPrimaryKey)
            {
                if (hasProperty)
                {
                    attributeBuilder.Append(" | ");
                }
                attributeBuilder.Append("ColumnProperties.PrimaryKey");
                hasProperty = true;
            }
            if (column.IsUnique)
            {
                if (hasProperty)
                {
                    attributeBuilder.Append(" | ");
                }
                attributeBuilder.Append("ColumnProperties.Unique");
                hasProperty = true;
            }
            if (!hasProperty)
            {
                attributeBuilder.Append("ColumnProperties.None");
            }

            if (column.Ordinal >= 0)
            {
                attributeBuilder.Append(", Ordinal=" + column.Ordinal);
            }
            if (column.MaxLength >= 0)
            {
                attributeBuilder.Append(", MaxLength=" + column.MaxLength);
            }
            if (!Compare.IsNullOrEmpty(column.DefaultValue))
            {
                attributeBuilder.Append(", DefaultValue=\"" + column.DefaultValue + "\"");
            }
        }