title: Change data type from int to long of key property in model .net Core 2.2
body: <p>I want to change the data type of the primary key of a model in ASP.Net core 2.2 from int to long since it is about to run out of the int range. The application was done code-first and uses SQL server as database.</p>
  
  <p>Changing the data type in the model works and running Add-Migration works too, but Update-Database fails with the error:</p>
  
  <pre><code>System.Data.SqlClient.SqlException (0x80131904): The index 'IX_tblMTransactions_OriginalTransactionId' is dependent on column 'OriginalTransactionId'.
  The object 'FK_tblMTransactions_tblMTransactions_OriginalTransactionId' is dependent on column 'OriginalTransactionId'.
  </code></pre>
  
  <p>So I read about it and it seems that there are some adjustments that need to be done to the migration like dropping foreign keys and indexes prior to the column change and bringing them back afterwards. Unfortunately I couldn't find any helpful information about doing this in .net core 2.2, the closest one I found was <a href="https://stackoverflow.com/questions/40512778/changing-primary-key-data-type-in-production-db">this question</a> but it talks about .net core 2.1 and the option <code>DropForeignKey</code> and <code>DropIndex</code>
  mentioned there don't seem to be available any longer on .net core 2.2 according to <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.migrations.migrationbuilder.dropforeignkey?view=efcore-2.1" rel="nofollow noreferrer">this article</a>.</p>
  
  <p>Here is the migration class:</p>
  
  <pre><code>public partial class _20190817_1746 : Migration
  {
      protected override void Up(MigrationBuilder migrationBuilder)
      {
          migrationBuilder.AlterColumn&lt;long&gt;(
              name: "OriginalTransactionId",
              table: "tblMTransactions",
              nullable: true,
              oldClrType: typeof(int),
              oldNullable: true);
  
          migrationBuilder.AlterColumn&lt;long&gt;(
              name: "Id",
              table: "tblMTransactions",
              nullable: false,
              oldClrType: typeof(int))
              .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
              .OldAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
      }
  
      protected override void Down(MigrationBuilder migrationBuilder)
      {
          migrationBuilder.AlterColumn&lt;int&gt;(
              name: "OriginalTransactionId",
              table: "tblMTransactions",
              nullable: true,
              oldClrType: typeof(long),
              oldNullable: true);
  
          migrationBuilder.AlterColumn&lt;int&gt;(
              name: "Id",
              table: "tblMTransactions",
              nullable: false,
              oldClrType: typeof(long))
              .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
              .OldAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
      }
  }
  </code></pre>
  
  <p>Here is a screenshot of the columns, keys and indexes of that table:
  <a href="https://i.stack.imgur.com/BX0cK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BX0cK.png" alt="Table"></a></p>
  
  <p>Does anybody know how to adjust the migration class in .NET Core 2.2 in order to make that work?</p>
  
  <p>Thanks</p>