Created
April 24, 2016 18:48
-
-
Save tdshipley/10e982fd9469d7cf76e0461bbd11177f to your computer and use it in GitHub Desktop.
Example of setting up cascade delete in EF Core using Fluent API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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