Why when setting Cascade delete between Parent and Child entity does it not create the Cascade in the migration?
Usual Blog / Post example:
class Blog
{
public int Id { get;set; }
public IList<Post> Posts { get;set;}
}
class Post
{
public int Id { get;set; }
public Blog Blog { get;set;}
}
In the EntityTypeConfiguration file
public override void Configure(EntityTypeBuilder<Notification> builder)
{
builder.HasMany(n => n.Posts).WithOne(e => e.Blog)
.OnDelete(DeleteBehavior.Cascade);
}
Why does it create the migration script of?
...
migrationBuilder.AddForeignKey(
name: "FK_Posts_Blogs_BlogId",
table: "Posts",
column: "BlogId",
principalTable: "Blogs",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
...
Note the
onDelete: ReferentialAction.Restrict
I understand that EF will actually do the cascade delete internally as long as you include the child objects for it to work through but why not leverage the Database Services cascade delete to be able to delete it in one command rather than 1 + n SQL commands i.e. 1 x Blog record & n x posts.
Imagine that there are 1000s of posts and you are deleting a blog.