public void Generate_can_output_create_index_statement() { var createTableOperation = new CreateTableOperation("Customers"); var idColumn = new ColumnModel(PrimitiveTypeKind.Int32) { Name = "Id", IsNullable = true, IsIdentity = true }; createTableOperation.Columns.Add(idColumn); createTableOperation.Columns.Add( new ColumnModel(PrimitiveTypeKind.String) { Name = "Name", IsNullable = false }); createTableOperation.PrimaryKey = new AddPrimaryKeyOperation(); createTableOperation.PrimaryKey.Columns.Add(idColumn.Name); var migrationSqlGenerator = new SqlCeMigrationSqlGenerator(); var createIndexOperation = new CreateIndexOperation { Table = createTableOperation.Name, IsUnique = true }; createIndexOperation.Columns.Add(idColumn.Name); var sql = migrationSqlGenerator.Generate( new[] { createIndexOperation }, "4.0").Join(s => s.Sql, Environment.NewLine); Assert.Contains( @"CREATE UNIQUE INDEX [IX_Id] ON [Customers]([Id])", sql); }
protected Tuple <string, IEnumerable <string> > Generate(ColumnModel column, string tableName) { var builder = new StringBuilder(); var additionalCommands = new List <string>(); var columnType = BuildPropertyType(column); builder.Append(Quote(column.Name)); builder.Append(" "); builder.Append(columnType); if ((column.IsNullable != null) && !column.IsNullable.Value) { builder.Append(" NOT NULL"); } if (column.DefaultValue != null) { builder.Append(" DEFAULT "); builder.Append(WriteValue((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { builder.Append(" DEFAULT "); builder.Append(column.DefaultValueSql); } else if (column.IsIdentity) { var identity = behavior.CreateIdentityForColumn(column.Name, tableName); additionalCommands.AddRange(identity.Where(x => !string.IsNullOrWhiteSpace(x))); } if (column.ClrType == typeof(bool)) { const string format = "ALTER TABLE \"{0}\" ADD CHECK (\"{1}\" IN (1,0));"; additionalCommands.Add(string.Format(format, tableName, column.Name)); } return(Tuple.Create(builder.ToString(), additionalCommands.AsEnumerable())); }
public async Task <IActionResult> PutColumn(Guid id, [FromBody] ColumnModel model) { var column = new ColumnModel() { Id = id, Name = model.Name, RoomId = model.RoomId, }; try { _context.Entry(column).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(column)); } catch (Exception ex) { throw ex; } }
private string ConstructSelectStatement(object dataModel) { var dataModelTable = dataModel.GetThuriaDataModelTableName(); var dataModelColumns = dataModel.GetThuriaDataModelColumns(TharkAction.Retrieve); var whereCondition = GetWhereConditionsForDataModel(TharkAction.Retrieve, dataModel); var selectStatementBuilder = _selectStatementBuilder.WithTable(dataModelTable); foreach (var currentColumn in dataModelColumns) { var columnModel = new ColumnModel(dataModelTable, currentColumn.ColumnName, currentColumn.Alias); selectStatementBuilder.WithColumn(columnModel); } if (!string.IsNullOrWhiteSpace(whereCondition)) { selectStatementBuilder.WithWhereCondition(whereCondition); } return(selectStatementBuilder.Build()); }
/// <summary> /// 获取字段类型 /// </summary> /// <param name="item"></param> /// <returns></returns> private static string GetFieldType(ColumnModel item) { switch (item.DataType.ToLower()) { case "char": case "nchar": case "varchar": case "nvarchar": case "varchar2": case "nvarchar2": return(string.Format("{0}({1})", item.DataType, item.Length)); case "decimal": case "numeric": case "number": return(string.Format("{0}({1},{2})", item.DataType, item.Precision, item.Scale)); default: return(item.DataType); } }
/// <summary> /// Edits the value of the specified object using the specified /// service provider and context /// </summary> /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information</param> /// <param name="isp">A service provider object through which editing services can be obtained</param> /// <param name="value">the value of the object under edit</param> /// <returns>The new value of the object. If the value is not changed, this should return the original value</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider isp, object value) { this.columnCollection = (ColumnCollection)value; foreach (Column column in this.columnCollection) { column.PropertyChanged += new ColumnEventHandler(this.column_PropertyChanged); } object newCollection = base.EditValue(context, isp, value); ColumnModel columns = (ColumnModel)context.Instance; if (columns.Table != null) { columns.Table.PerformLayout(); columns.Table.Refresh(); } return(newCollection); }
void GetColumns() { foreach (var x in _tables) { using (var command = new MySqlCommand(string.Format(GetColumnsQuery, x.Key), _connection)) using (var reader = command.ExecuteReader()) while (reader.Read()) { var column = new ColumnModel { Table = x.Value, PrimaryKeyOrdinal = reader[3].ToString() == "PRI" ? (int?)1 : null, Name = reader.GetString(0), DataType = reader.GetString(1), IsNullable = reader.GetString(2) == "YES", DefaultValue = reader[4].ToString() == "" ? null : reader[4].ToString(), }; x.Value.Columns.Add(column); } } }
public List <TableModel> ListAllTables() { List <TableModel> tables = new List <TableModel>(); using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DatabaseDataSourcesConnectionString)) { conn.Open(); using (SqlCommand command = new SqlCommand("select table_name from information_schema.tables where table_catalog = 'SqlConfidenceData'", conn)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { TableModel model = new TableModel(); model.TableName = (String)reader["table_name"]; tables.Add(model); } reader.Close(); } foreach (var table in tables) { using (SqlCommand command = new SqlCommand("select column_name, data_type from information_Schema.columns where table_name = @TableName", conn)) { command.Parameters.AddWithValue("TableName", table.TableName); SqlDataReader reader = command.ExecuteReader(); table.Columns = new List <ColumnModel>(); while (reader.Read()) { ColumnModel column = new ColumnModel(); column.Name = (String)reader["column_name"]; column.Type = (String)reader["data_type"]; table.Columns.Add(column); } reader.Close(); } } } return(tables); }
private DataTemplate CellTemplateFor(ColumnModel column) { var key = column.Index.ToString(); var tBlockStyleTriggerForeground = new DataTrigger { Binding = new Binding($"{key}_color"), Value = "SecondaryTextBrush" }; tBlockStyleTriggerForeground.Setters.Add(new Setter(TextBlock.ForegroundProperty, Brushes.LightGray)); var tBlockStyle = new Style(typeof(TextBlock)); tBlockStyle.Setters.Add(new Setter(TextBlock.ForegroundProperty, Brushes.Black)); tBlockStyle.Triggers.Add(tBlockStyleTriggerForeground); var tBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); tBlockFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center); tBlockFactory.SetValue(FrameworkElement.MarginProperty, new Thickness(3, 0, 3, 2)); tBlockFactory.SetValue(TextBlock.TextProperty, new Binding(key)); tBlockFactory.SetValue(TextBlock.TextTrimmingProperty, TextTrimming.CharacterEllipsis); tBlockFactory.SetValue(FrameworkElement.StyleProperty, tBlockStyle); if (column.IsNumeric) { tBlockFactory.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); } else if (column.IsBool) { tBlockFactory.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); } var gridFactory = new FrameworkElementFactory(typeof(Grid)); gridFactory.SetValue(Panel.BackgroundProperty, Brushes.Transparent); gridFactory.AppendChild(tBlockFactory); return(new DataTemplate { VisualTree = gridFactory }); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } ColumnModel other = (ColumnModel)obj; if (string.ReferenceEquals(name, null)) { if (!string.ReferenceEquals(other.name, null)) { return(false); } } else if (!name.Equals(other.name)) { return(false); } if (table == null) { if (other.table != null) { return(false); } } else if (!table.Equals(other.table)) { return(false); } return(true); }
private static string GenerateColumnEncrypted(ColumnModel column, string command) { // Obtain annotation info AnnotationValues values; column.Annotations.TryGetValue(ColumnEncryptedWithAnnotationConvention.AnnotationName, out values); if (values == null) { return(command); } // Do SQL generation for column using annotation value as appropriate. var value = values.NewValue as string; // Exit if no value is defined. if (value == null) { return(command); } // Remove any other default collation if this is a string. // String fields need to have BIN2 collation. var collate = string.Empty; if (column.ClrType == typeof(string)) { collate = " COLLATE Latin1_General_BIN2"; var indexOfCollation = command.IndexOf(" COLLATE ", StringComparison.InvariantCulture); if (indexOfCollation > 0) { command = command.Remove(indexOfCollation); } } // Bind the constraint. var config = EncryptedWithConfiguration.Deserialize(value); var encryptionType = config.Type.ToString().ToUpperInvariant(); return(command + $"{collate} ENCRYPTED WITH (ENCRYPTION_TYPE = {encryptionType}, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = {config.KeyName}) "); }
//POST : /api/Warehouse/column/post public async Task <Object> PostColumn(ColumnModel model) { var column = new ColumnModel() { Id = Guid.NewGuid(), Name = model.Name, RoomId = model.RoomId, }; try { var result = await _context.Columns.AddAsync(column); await _context.SaveChangesAsync(); return(Ok(column)); } catch (Exception ex) { throw ex; } }
public override void Down() { base.CreateTable("dbo.StoredFiles", (ColumnBuilder c) => { ColumnModel columnModel = c.Guid(new bool?(false), false, null, null, null, null, null); int?nullable = null; bool?nullable1 = null; bool?nullable2 = nullable1; nullable1 = null; ColumnModel columnModel1 = c.String(new bool?(false), nullable, nullable2, nullable1, null, null, null, null, null); nullable1 = null; bool?nullable3 = nullable1; nullable = null; nullable1 = null; bool?nullable4 = nullable1; nullable1 = null; ColumnModel columnModel2 = c.String(nullable3, nullable, nullable4, nullable1, null, null, null, null, null); nullable = null; nullable1 = null; return(new { Id = columnModel, FileName = columnModel1, FileType = columnModel2, Bytes = c.Binary(new bool?(false), nullable, nullable1, null, null, false, null, null, null) }); }, null).PrimaryKey((t) => t.Id, null, true, null); base.DropTable("dbo.AbpBinaryObjects"); }
public ColumnViewModel(MainAreaViewModel parent, ColumnModel model) { this._parent = parent; this._model = model; this.CompositeDisposable.Add( this._tabs = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx( model.Tabs, _ => new TabViewModel(this, _), DispatcherHelper.UIDispatcher)); this.CompositeDisposable.Add( Observable.FromEvent( h => this._model.CurrentFocusTabChanged += h, h => this._model.CurrentFocusTabChanged -= h) .Select(_ => this._model.CurrentFocusTabIndex) .Subscribe(this.UpdateFocusFromModel)); this.CompositeDisposable.Add(_tabs.ListenCollectionChanged(_ => this._tabs.ForEach(item => item.UpdateFocus()))); if (this._tabs.Count > 0) { this.FocusedTab = this._tabs[0]; } }
public override void Up() { Dictionary <string, object> strs = new Dictionary <string, object>() { { "DynamicFilter_TenantDateTimeSettings_MustHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" }, { "DynamicFilter_TenantDateTimeSettings_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" } }; base.CreateTable("dbo.FuelWerxTenantDateTimeSettings", (ColumnBuilder c) => { long?nullable = null; ColumnModel columnModel = c.Long(new bool?(false), true, nullable, null, null, null, null); ColumnModel columnModel1 = c.Int(new bool?(false), false, null, null, null, null, null); bool?nullable1 = null; bool?nullable2 = nullable1; nullable1 = null; ColumnModel columnModel2 = c.String(new bool?(false), new int?(1200), nullable2, nullable1, null, null, null, null, null); nullable1 = null; ColumnModel columnModel3 = c.Boolean(new bool?(false), nullable1, null, null, null, null); nullable1 = null; nullable = null; ColumnModel columnModel4 = c.Long(nullable1, false, nullable, null, null, null, null); nullable1 = null; byte?nullable3 = null; DateTime?nullable4 = null; ColumnModel columnModel5 = c.DateTime(nullable1, nullable3, nullable4, null, null, null, null); nullable1 = null; nullable3 = null; nullable4 = null; ColumnModel columnModel6 = c.DateTime(nullable1, nullable3, nullable4, null, null, null, null); nullable1 = null; nullable = null; ColumnModel columnModel7 = c.Long(nullable1, false, nullable, null, null, null, null); nullable3 = null; nullable4 = null; nullable1 = null; nullable = null; return(new { Id = columnModel, TenantId = columnModel1, TimezoneJson = columnModel2, IsDeleted = columnModel3, DeleterUserId = columnModel4, DeletionTime = columnModel5, LastModificationTime = columnModel6, LastModifierUserId = columnModel7, CreationTime = c.DateTime(new bool?(false), nullable3, nullable4, null, null, null, null), CreatorUserId = c.Long(nullable1, false, nullable, null, null, null, null) }); }, strs, null).PrimaryKey((t) => t.Id, null, true, null); }
private void SetAnnotatedColumn(ColumnModel column, string tableName) { AnnotationValues values; if (column.Annotations.TryGetValue("SqlDefaultValue", out values)) { if (values.NewValue == null) { column.DefaultValueSql = null; using (var writer = Writer()) { // Drop Constraint writer.WriteLine(GetSqlDropConstraintQuery(tableName, column.Name)); Statement(writer); } } else { column.DefaultValueSql = (string)values.NewValue; } } }
protected override RelationalTypeMapping GetTypeMapping(ColumnModel column) { Check.NotNull(column, nameof(column)); var postgresType = column.Npgsql().PostgresTypeType; switch (postgresType) { case PostgresTypeType.Base: return(base.GetTypeMapping(column)); case PostgresTypeType.Array: return(GetArrayTypeMapping(column)); case PostgresTypeType.Range: case PostgresTypeType.Enum: case PostgresTypeType.Composite: default: Logger.LogWarning($"Can't scaffold PostgreSQL {postgresType} for column '{column.Name}' of type '{column.DataType}'"); return(null); } }
//Methods------------------------------------------------------------------------------- public bool changeColumnName(BoardModel board, ColumnModel column, ColumnModel backupColumn) { Message = ""; try { if (!string.IsNullOrWhiteSpace(Name)) //Column name cant be null or white spaces { controller.changeColumnName(column, board.user.Email, column.Ordinal, Name, backupColumn); return(true); } else { Message = "plese enter new name"; //Raise error message return(false); } } catch (Exception e) { Message = e.Message; //Raise error message return(false); } }
public void Generate_can_output_create_table_statement_with_non_clustered_pk() { var createTableOperation = new CreateTableOperation("foo.Customers"); var idColumn = new ColumnModel(PrimitiveTypeKind.Int32) { Name = "Id", IsNullable = true, IsIdentity = true }; createTableOperation.Columns.Add(idColumn); createTableOperation.Columns.Add( new ColumnModel(PrimitiveTypeKind.String) { Name = "Name", IsNullable = false }); createTableOperation.PrimaryKey = new AddPrimaryKeyOperation { IsClustered = false }; createTableOperation.PrimaryKey.Columns.Add(idColumn.Name); var migrationSqlGenerator = new SqlServerMigrationSqlGenerator(); var sql = migrationSqlGenerator.Generate(new[] { createTableOperation }, "2008").Join(s => s.Sql, Environment.NewLine); Assert.Contains( @"IF schema_id('foo') IS NULL EXECUTE('CREATE SCHEMA [foo]') CREATE TABLE [foo].[Customers] ( [Id] [int] IDENTITY, [Name] [nvarchar](max) NOT NULL, CONSTRAINT [PK_foo.Customers] PRIMARY KEY NONCLUSTERED ([Id]) )", sql); }
public override void Up() { Dictionary <string, object> strs = new Dictionary <string, object>() { { "DynamicFilter_ProjectProduct_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" } }; base.CreateTable("dbo.FuelWerxProjectProducts", (ColumnBuilder c) => { long?nullable = null; ColumnModel columnModel = c.Long(new bool?(false), true, nullable, null, null, null, null); nullable = null; ColumnModel columnModel1 = c.Long(new bool?(false), false, nullable, null, null, null, null); nullable = null; ColumnModel columnModel2 = c.Long(new bool?(false), false, nullable, null, null, null, null); bool?nullable1 = null; ColumnModel columnModel3 = c.Boolean(new bool?(false), nullable1, null, null, null, null); nullable1 = null; ColumnModel columnModel4 = c.Boolean(new bool?(false), nullable1, null, null, null, null); nullable1 = null; nullable = null; ColumnModel columnModel5 = c.Long(nullable1, false, nullable, null, null, null, null); nullable1 = null; byte?nullable2 = null; DateTime?nullable3 = null; ColumnModel columnModel6 = c.DateTime(nullable1, nullable2, nullable3, null, null, null, null); nullable1 = null; nullable2 = null; nullable3 = null; ColumnModel columnModel7 = c.DateTime(nullable1, nullable2, nullable3, null, null, null, null); nullable1 = null; nullable = null; ColumnModel columnModel8 = c.Long(nullable1, false, nullable, null, null, null, null); nullable2 = null; nullable3 = null; nullable1 = null; nullable = null; return(new { Id = columnModel, ProjectId = columnModel1, ProductId = columnModel2, IsActive = columnModel3, IsDeleted = columnModel4, DeleterUserId = columnModel5, DeletionTime = columnModel6, LastModificationTime = columnModel7, LastModifierUserId = columnModel8, CreationTime = c.DateTime(new bool?(false), nullable2, nullable3, null, null, null, null), CreatorUserId = c.Long(nullable1, false, nullable, null, null, null, null) }); }, strs, null).PrimaryKey((t) => t.Id, null, true, null).ForeignKey("dbo.FuelWerxProducts", (t) => t.ProductId, true, null, null).ForeignKey("dbo.FuelWerxProjects", (t) => t.ProjectId, true, null, null).Index((t) => t.ProjectId, null, false, false, null).Index((t) => t.ProductId, null, false, false, null); }
protected virtual string GetPropertyName([NotNull] ColumnModel column) { Check.NotNull(column, nameof(column)); var table = column.Table ?? _nullTable; var usedNames = new List <string>(); // TODO - need to clean up the way CSharpNamer & CSharpUniqueNamer work (see issue #1671) if (column.Table != null) { usedNames.Add(_tableNamer.GetName(table)); } if (!_columnNamers.ContainsKey(table)) { _columnNamers.Add(table, new CSharpUniqueNamer <ColumnModel>( c => CandidateNamingService.GenerateCandidateIdentifier(c.Name), usedNames)); } return(_columnNamers[table].GetName(column)); }
private ColumnModel FindColumnForForeignKey( string columnName, TableModel table, string fkName) { ColumnModel column = null; if (string.IsNullOrEmpty(columnName)) { Logger.LogWarning( SqlServerDesignStrings.ColumnNameEmptyOnForeignKey( table.SchemaName, table.Name, fkName)); return(null); } if (!_tableColumns.TryGetValue( ColumnKey(table, columnName), out column)) { Logger.LogWarning( SqlServerDesignStrings.UnableToFindColumnForForeignKey( fkName, columnName, table.SchemaName, table.Name)); return(null); } return(column); }
protected virtual MigrationStatement Generate(AlterColumnOperation op) { if (op == null) { return(null); } ColumnModel column = op.Column; StringBuilder sb = new StringBuilder(); _tableName = op.Table; // for existing columns sb.Append("alter table `" + TrimSchemaPrefix(op.Table) + "` modify `" + column.Name + "` "); // add definition sb.Append(Generate(column)); return(new MigrationStatement { Sql = sb.ToString() }); }
public static Task <IReadOnlyCollection <ColumnModel> > CreateColumns(this IReadOnlyCollection <TableResult> tableResults) { var columns = new List <ColumnModel>(); foreach (var tableResult in tableResults) { var maxLength = tableResult.MaxLength; if (tableResult.DataType.Equals("nvarchar", StringComparison.InvariantCultureIgnoreCase) && maxLength != null) { maxLength /= 2; } var columnModel = new ColumnModel { Id = tableResult.ColumnId, Name = tableResult.Column, Nullable = tableResult.Nullable, IdentityColumn = tableResult.Identity, DataType = tableResult.DataType, MaxLength = maxLength, Precision = tableResult.Precision, Scale = tableResult.Scale, SeedValue = tableResult.SeedValue, IncrementValue = tableResult.IncrementValue, DefaultValue = tableResult.DefaultValue }; columns.Add(columnModel); } columns = columns .OrderBy(c => c.Name) .ToList(); return(Task.FromResult((IReadOnlyCollection <ColumnModel>)columns)); }
/// <summary> /// Generates SQL for the given column model. This method is called by other methods that /// process columns and can be overridden to change the SQL generated. /// </summary> /// <param name="column">The column for which SQL is being generated.</param> /// <param name="writer">The writer to which generated SQL should be written.</param> protected internal void Generate(ColumnModel column, IndentedTextWriter writer) { Check.NotNull(column, "column"); Check.NotNull(writer, "writer"); writer.Write(Quote(column.Name)); writer.Write(" "); writer.Write(BuildColumnType(column)); if ((column.IsNullable != null) && !column.IsNullable.Value) { writer.Write(" NOT NULL"); } if (column.DefaultValue != null) { writer.Write(" DEFAULT "); writer.Write(Generate((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { writer.Write(" DEFAULT "); writer.Write(column.DefaultValueSql); } else if (column.IsIdentity) { if ((column.Type == PrimitiveTypeKind.Guid) && (column.DefaultValue == null)) { writer.Write(" DEFAULT " + GuidColumnDefault); } else { writer.Write(" IDENTITY"); } } }
private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperation) { SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ADD COLUMN "); ColumnModel column = migrationOperation.Column; ddlBuilder.AppendIdentifier(column.Name); TypeUsage storeType = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity); //DEFAULT VALUE if (column.DefaultValue != null) { if (column.DefaultValue is DateTime defaultValue) { var format = "yyyy-MM-dd HH:mm:ss.ffffff"; if (defaultValue.Kind == DateTimeKind.Utc) { format += 'Z'; } ddlBuilder.AppendSql($" DEFAULT '{defaultValue.ToString(format)}'"); } } else if (!String.IsNullOrEmpty(column.DefaultValueSql)) { ddlBuilder.AppendSql($" DEFAULT "); ddlBuilder.AppendSql(column.DefaultValueSql); } ddlBuilder.AppendNewLine(); return(ddlBuilder.GetCommandText()); }
protected virtual string Generate(ColumnModel column) { var result = new StringBuilder(); result.Append(Quote(column.Name)); result.Append(" "); result.Append(BuildColumnType(column)); if ((column.IsNullable != null) && !column.IsNullable.Value) { result.Append(" NOT NULL"); } if (column.DefaultValue != null) { result.Append(" DEFAULT "); result.Append(WriteValue((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { result.Append(" DEFAULT "); result.Append(column.DefaultValueSql); } else if (column.IsIdentity) { if (column.Type == PrimitiveTypeKind.Guid && column.DefaultValue == null) { result.Append(" DEFAULT " + Guid.NewGuid().ToNuoDbString()); } else { result.Append(" GENERATED BY DEFAULT AS IDENTITY"); } } return(result.ToString()); }
private void SetAuditColumnDefaults(ColumnModel column, string tableName) { HandleSqlDefaultValueAttribute(column, tableName); HandleDefaultValueAttribute(column, tableName); List <string> dateTimeColumsns = new List <string> { "UpdatedAt", "CreatedAt" }; List <string> booleanColumnsWithDefaultTrue = new List <string> { "IsActive" }; List <string> booleanColumnsWithDefaultFalse = new List <string> { "IsDeleted" }; List <string> guidColumns = new List <string> { }; if (guidColumns.Any(col => string.Compare(column.Name, col, System.StringComparison.InvariantCultureIgnoreCase) == 0) && column.Type == PrimitiveTypeKind.Guid) { column.DefaultValueSql = "NEWID()"; } if (dateTimeColumsns.Any(col => string.Compare(column.Name, col, System.StringComparison.InvariantCultureIgnoreCase) == 0)) { column.DefaultValueSql = "GETUTCDATE()"; } if (booleanColumnsWithDefaultTrue.Any(col => string.Compare(column.Name, col, System.StringComparison.InvariantCultureIgnoreCase) == 0)) { column.DefaultValue = "1"; } if (booleanColumnsWithDefaultFalse.Any(col => string.Compare(column.Name, col, System.StringComparison.InvariantCultureIgnoreCase) == 0)) { column.DefaultValue = "0"; } }
private void Generate(ColumnModel column, TextWriter writer, bool isAlter = false) { Contract.Requires(column != null); Contract.Requires(writer != null); writer.Write(Quote(column.Name)); writer.Write(" {0}", isAlter ? "TYPE " : ""); writer.Write(BuildColumnType(column)); // check if it has a max length if (column.MaxLength != null && column.MaxLength > 0) { writer.Write("({0})", column.MaxLength); } // check if it's nullable if ((column.IsNullable != null) && !column.IsNullable.Value && isAlter == false) { writer.Write(" NOT NULL"); } // check if it has a default value if (column.DefaultValue != null) { writer.Write(" DEFAULT "); writer.Write(Generate((dynamic)column.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(column.DefaultValueSql)) { writer.Write(" DEFAULT "); writer.Write(column.DefaultValueSql); } }
private List <ColumnModel> ReadAll(DbDataReader reader) { var result = new List <ColumnModel>(); using (reader) { while (reader.Read()) { var model = new ColumnModel(); model.TABLE_SCHEMA = reader.GetFieldValue <string>(0); model.TABLE_NAME = reader.GetString(1); model.COLUMN_NAME = reader.GetString(2); model.IS_NULLABLE = reader.GetString(3); model.DATA_TYPE = reader.GetString(4); model.COLUMN_TYPE = reader.GetString(5); model.COLUMN_KEY = reader.GetString(6); model.EXTRA = reader.GetString(7); model.COLUMN_COMMENT = reader.GetString(8); result.Add(model); } } return(result); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public SqlServerColumnModelAnnotations([NotNull] ColumnModel column) { Check.NotNull(column, nameof(column)); _column = column; }
/// <summary> /// Initializes a new instance of the ColumnCollectionEditor class /// using the specified collection type /// </summary> /// <param name="type">The type of the collection for this editor to edit</param> public ColumnCollectionEditor(Type type) : base(type) { this.columns = null; this.previewColumnModel = new ColumnModel(); this.previewColumnModel.Columns.Add(new TextColumn("Column", 116)); this.previewTableModel = new TableModel(); this.previewTableModel.Rows.Add(new Row()); Cell cell = new Cell(); cell.Editable = false; cell.ToolTipText = "This is a Cell ToolTip"; this.previewTableModel.Rows[0].Cells.Add(cell); this.previewTableModel.RowHeight = 20; this.previewTable = new Table(); this.previewTable.Preview = true; this.previewTable.Size = new Size(120, 274); this.previewTable.Location = new Point(246, 24); this.previewTable.GridLines = GridLines.Both; this.previewTable.TabStop = false; this.previewTable.EnableToolTips = true; this.previewTable.ColumnModel = this.previewColumnModel; this.previewTable.TableModel = this.previewTableModel; this.previewLabel = new Label(); this.previewLabel.Text = "Preview:"; this.previewLabel.Size = new Size(140, 16); this.previewLabel.Location = new Point(247, 8); }