Categories
c# entity-framework entity-framework-4 sql

How to cascade delete in entity framework?

I have two objects in my model

Car and carPart

with 1:n relationship.

I want to delete cascade the entity car.
when I delete i get the following exception :

 The operation failed: The relationship could not be changed because one or 
more of the foreign-key properties is non-nullable. When a change is made
to a relationship, the related foreign-key property is set to a null value.
If the foreign-key does not support null values, a new relationship must
be defined, the foreign-key property must be assigned another non-null value,
or the unrelated object must be deleted.

I think it tries to delete the car object first and then the car parts.

Which is imposiible due to the foreign key.

How do I handle this ?

I want, obviously to delete the carPart first and then only the car.

Thanks.