This is my ef migration code ,
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "ColumnNew",
table: "MyTableName",
nullable: true);
}
So , my new column name is ColumnNew . I already have ColumnOne and ColumnTwo.
My question is, if ColumnOne's value is equal to 1 , I want to copy ColumnTwo's value to ColumnNew .
Can I do this in migration file ?
You have to add an update statement after creating the new column:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "ColumnNew",
table: "MyTableName",
nullable: true);
migrationBuilder.Sql("UPDATE MyTableName SET ColumnNew = ColumnTwo WHERE ColumnOne = 1");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With