/// <summary> /// Generates the custom column code. /// </summary> /// <param name="writer">The writer.</param> /// <param name="fullTableName">Full name of the table.</param> /// <param name="columnName">Name of the column.</param> private void GenerateCustomColumnCode(System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer, string fullTableName, string columnName) { string tableName = fullTableName.Replace("dbo.", string.Empty); if (dbContextEntities.ContainsKey(tableName)) { Type tableType = dbContextEntities[tableName]; if (tableType != null) { MemberInfo mi = tableType.GetMember(columnName).FirstOrDefault(); if (mi != null) { AlternateKeyAttribute attribute = mi.GetCustomAttribute <AlternateKeyAttribute>(); if (attribute != null) { writer.WriteLine("CreateIndex( \"" + fullTableName + "\", \"" + columnName + "\", true );"); writer.WriteLine(""); } } else { // probably not found if this is the Down() migration } } } else { // probably not found if this is the Down() migration } }
/// <summary> /// Generates the custom column code. /// </summary> /// <param name="writer">The writer.</param> /// <param name="fullTableName">Full name of the table.</param> /// <param name="columnName">Name of the column.</param> private void GenerateCustomColumnCode(System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer, string fullTableName, string columnName) { string tableName = fullTableName.Replace("dbo.", string.Empty); Type tableType = null; try { tableType = tableNameLookup[tableName]; } catch (Exception ex) { writer.WriteLine("// TableName: " + tableName); writer.WriteLine("// " + ex.Message); } if (tableType != null) { MemberInfo mi = tableType.GetMember(columnName).FirstOrDefault(); if (mi != null) { AlternateKeyAttribute attribute = mi.GetCustomAttribute <AlternateKeyAttribute>(); if (attribute != null) { writer.WriteLine("CreateIndex( \"" + fullTableName + "\", \"" + columnName + "\", true );"); } } else { // probably not found if this is the Down() migration } } else { // probably not found if this is the Down() migration } }
protected override void Generate(System.Data.Entity.Migrations.Model.AddPrimaryKeyOperation addPrimaryKeyOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer) { addPrimaryKeyOperation.IsClustered = false; base.Generate(addPrimaryKeyOperation, writer); }
protected override void Generate(System.Data.Entity.Migrations.Model.MoveTableOperation moveTableOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer) { moveTableOperation.CreateTableOperation.PrimaryKey.IsClustered = false; base.Generate(moveTableOperation, writer); }
//EF 6.0 protected override void GenerateMakeSystemTable(CreateTableOperation createTableOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer) { }
/// <summary> /// Generates code to perform an <see cref="T:System.Data.Entity.Migrations.Model.AddColumnOperation" />. /// </summary> /// <param name="addColumnOperation">The operation to generate code for.</param> /// <param name="writer">Text writer to add the generated code to.</param> protected override void Generate(System.Data.Entity.Migrations.Model.AddColumnOperation addColumnOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer) { base.Generate(addColumnOperation, writer); GenerateCustomColumnCode(writer, addColumnOperation.Table, addColumnOperation.Column.Name); }
/// <summary> /// Generates code to perform a <see cref="T:System.Data.Entity.Migrations.Model.CreateTableOperation" />. /// </summary> /// <param name="createTableOperation">The operation to generate code for.</param> /// <param name="writer">Text writer to add the generated code to.</param> protected override void Generate(System.Data.Entity.Migrations.Model.CreateTableOperation createTableOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter writer) { base.Generate(createTableOperation, writer); foreach (var column in createTableOperation.Columns) { GenerateCustomColumnCode(writer, createTableOperation.Name, column.Name); } }