Skip to content

Instantly share code, notes, and snippets.

@tdshipley
Created April 24, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdshipley/10e982fd9469d7cf76e0461bbd11177f to your computer and use it in GitHub Desktop.
Save tdshipley/10e982fd9469d7cf76e0461bbd11177f to your computer and use it in GitHub Desktop.
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