static void DeleteRelatedEntities <T>(T entity, EFRecipesEntities context)
            where T : EntityObject
        {
            var entities = ((IEntityWithRelationships)entity)
                           .RelationshipManager.GetAllRelatedEnds()
                           .SelectMany(e =>
                                       e.CreateSourceQuery().OfType <EntityObject>()).ToList();

            foreach (var child in entities)
            {
                context.DeleteObject(child);
            }
            context.SaveChanges();
        }
 static void RunExample()
 {
     using (var context = new EFRecipesEntities())
     {
         var recipe1 = new Recipe {
             RecipeName = "Chicken Risotto"
         };
         var recipe2 = new Recipe {
             RecipeName = "Baked Chicken"
         };
         recipe1.Steps.Add(new Step {
             Description = "Bring Broth to a boil"
         });
         recipe1.Steps.Add(new Step
         {
             Description =
                 "Slowly add Broth to Rice"
         });
         recipe1.Ingredients.Add(new Ingredient {
             Name = "1 Cup White Rice"
         });
         recipe1.Ingredients.Add(new Ingredient
         {
             Name =
                 "6 Cups Chicken Broth"
         });
         recipe2.Steps.Add(new Step
         {
             Description =
                 "Bake at 350 for 35 Minutes"
         });
         recipe2.Ingredients.Add(new Ingredient {
             Name = "1 lb Chicken"
         });
         context.Recipes.AddObject(recipe1);
         context.Recipes.AddObject(recipe2);
         context.SaveChanges();
         Console.WriteLine("All the Related Entities...");
         ShowRecipes();
         DeleteRelatedEntities(recipe2, context);
         Console.WriteLine("\nAfter Related Entities are Deleted...");
         ShowRecipes();
     }
 }