2012-11-22 3 views
4

나는 나의 모델엔티티 프레임 워크에서 계단식 삭제 방법은 무엇입니까? N 관계 :

차와 1 carPart

에 두 개체가 있습니다.

엔티티 카를 캐스케이드 삭제하고 싶습니다.

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. 

내가 먼저 다음 자동차 부품을 자동차 객체를 삭제하려고 생각 : 나는 삭제할 때 나는 다음과 같은 예외를 얻을.
외래 키로 인해 불가능한 것입니다.

어떻게 처리합니까?
분명히 carPart를 먼저 지우고 차를 지우고 싶습니다.
감사합니다.

답변

6

삭제할 때 캐스케이드하려는 데이터베이스를 지정해야합니다. 그러면 Entity Framework에서 예상 한대로 작업을 수행합니다. SQL Server 관리 Studio에서 테이블에 대한 Relationships 화면으로 이동하는 경우는 FK 동작을 변경할 수 있습니다 :이 답변

Cascade delete in Sql Server Management Studio

+0

감사합니다! –

1

계단식 삭제를 원할 경우 데이터베이스 수준에서 계단식 삭제를 설정하십시오. SQL이 (가) 삭제할 수 없으므로 오류가 발생했습니다.

Entity Framework에서는이 작업을 수행 할 필요가 없습니다.

관련 문제