Started a new ASP.NET MVC 3 application and getting the following error:
The primary key value cannot be deleted because references to this key stil
Found the solution:
public class FoodJournalEntities : DbContext
{
public DbSet Journals { get; set; }
public DbSet JournalEntries { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasOptional(j => j.JournalEntries)
.WithMany()
.WillCascadeOnDelete(true);
base.OnModelCreating(modelBuilder);
}
}
Source