Entity Framework(MySQL/Connector)を介して外部キー関係を持つオブジェクトを削除しようとしています。MySQL + Entity Framework:オブジェクトを削除できません
ClientAccount >>> ClientEmailAddresses
foreach (ClientAccount client in recsClientStore.Deleted) {
ClientAccount stub = new ClientAccount();
stub.Id = client.Id;
this.DBContext.AttachTo("ClientAccounts", stub);
stub.FkClientEmailAddresses.Clear();
this.DBContext.DeleteObject(stub);
}
this.DBContext.SaveChanges();
..しかし、私はこれを行うとき、私は次のエラーを取得する:
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.
は、私は、これは私の葉どこ本当にわかりません。最初にEmailAddressオブジェクトを削除する必要がありますか?私たちはカスケードをオンにすることには注意していますが、これは外来キーを整理するために必要なものです。
stub.FkClientEmailAddresses.Clear();
関係を削除しません:
ありがとうございます。カスケーディングが本当に必要かどうかを確かめるために構造を見直すつもりです。 – pierre