我有以下代码
public class Post
{
public int Id { get; set; }
public ICollection<Comment> Comments { get; set; }
}
public class Comment
{
public int Id { get; set; }
public int PostId { get; set; }
public virtual Post Post { get; set; }
}
public override void Configure(EntityTypeBuilder<Comment> modelBuilder)
{
modelBuilder.ToTable(nameof(Comment));
modelBuilder.HasKey(comment => comment.id);
modelBuilder.HasOne(comment => comment.Post)
.HasMany(post => post.Comments)
.HasForeignKey(comment => comment.PostId)
.OnDelete(DeleteBehaviour.Cascade);
}
因此,当我删除帖子时,与帖子相关的评论也会被删除吗?