Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of setting up cascade delete in EF Core using Fluent API
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Metadata;
public class MyDBContext : DBContext
{
public DbSet<Blog> Blog { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.HasOne(p => p.Blog)
.WithMany(b => b.Posts)
.OnDelete(DeleteBehavior.Cascade);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment