4

モデルに 2 つのオブジェクトがあります

車と車のパーツ

1:n の関係で。

実体車のカスケードを削除したい。削除すると、次の例外が発生します。

 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 を削除してから車だけを削除したいと思います。
ありがとう。

4

2 に答える 2

1

カスケード削除が必要な場合は、データベース レベルでカスケード削除をセットアップします。SQLは削除を許可していないため、エラーが発生しています。

Entity Framework で行う必要はありません。

于 2012-11-22T10:47:27.090 に答える