Skip to content

Instantly share code, notes, and snippets.

@josephhhhh
Last active March 15, 2018 03:25
Show Gist options
  • Save josephhhhh/52edc7c5c66b8cda819b03932f604c80 to your computer and use it in GitHub Desktop.
Save josephhhhh/52edc7c5c66b8cda819b03932f604c80 to your computer and use it in GitHub Desktop.
namespace CascadeDelete.Models
{
public class DataContext: DbContext
{
public virtual DbSet<Resident> Residents { get; set; }
public virtual DbSet<City> Cities { get; set; }
public virtual DbSet<ResidentCityOwn> ResidentCityOwn { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Fluent API configurations
modelBuilder.Entity<Resident>()
.HasRequired(e => e.City)
.WithMany(e => e.Residents)
.WillCascadeOnDelete(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment