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(); }