I have a question about cascade deletes in sql server. I have two tables: Employee and Degree with a one to many relation. Now I want to delete Employee, but I get an error because there is a relation with degree. How can I delete the related information when I delete an employee?
After research I found that you can use cascade delete. I tried this without success. I have read the following topics.
How do I use cascade delete with SQL Server?
I have added this code to my EmployeeController, without success
protected void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder
.Entity<Employee>()
.HasMany(x => x.Degrees)
.WithRequired(x => x.Employee)
.WillCascadeOnDelete();
}
And I tried changing the delete option to cascade, what is shown in this topic:
SQL Server 2005 Cascading Delete
But so far without success. So how can I delete an employee with his relations.