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 객체를 삭제해야합니까? 우리는 캐스케이드 (cascade)를 돌보는 것을 경계하고 있지만 외래 키를 정리하기 위해 점점 더 필요해 보이는 것처럼 보입니다.
stub.FkClientEmailAddresses.Clear();
관계를 삭제하지 않습니다
감사합니다. 우리가 실제로 계단식이 필요한지 여부를 확인하기 위해 구조를 다시 검토 할 것입니다. – pierre