Database Reference
In-Depth Information
Figure 12-7. The cascade delete rule from the database was imported into the model, and it is shown in the properties
for the association
The cascade delete shown in Figure 12-7 is in the conceptual layer. There is a similar rule present in the store
layer. Both of these Entity Framework rules and the underlying database cascade delete rule are necessary to keep the
object context and the database in sync when objects are deleted.
The code in Listing 12-5 demonstrates the cascade delete.
Listing 12-5. Using the Underlying Cascade Delete Rules to Delete the Related Objects
class Program
{
static void Main(string[] args)
{
RunExample();
}
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
var course1 = new Course { CourseName = "CS 301" };
var course2 = new Course { CourseName = "Math 455" };
var en1 = new Enrollment { Student = "James Folk" };
Search WWH ::




Custom Search