I have the following two tables:
-Table1 (Principal) -Table2
Entities:
public partial class Table2
{
public int Table2Id{ get; set; }
public int Tabl1Id{ get; set; }
public virtual Table1 Table1 { get; set; }
}
public partial class Table1
{
public virtual ICollection<Table2> Table2Items { get; set; }
}
For this I create the following mapping:
modelBuilder.Entity<Table2>()
.HasOne(e => e.Table1 )
.WithMany(e => e.Table2Items)
.HasForeignKey(e => e.Table1Id)
.OnDelete(DeleteBehavior.Restrict);
This gives me the following piece of code in the migration file:
migrationBuilder.AddForeignKey(
name: "FK_Table2_Table1_Table1Id",
table: "Table2",
column: "Table1Id",
principalTable: "Table1",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
How come that my migration is still resolving the cascade behaviour for this relationship?