我有这个领域:
public class Phone {
public int Id { get; set; }
public string Number { get; set; }
public Person Person { get; set; }
}
public class Person {
public int Id { get; set; }
public IList<Phone> Phones { get; set; }
}
I load a Person
and clear its Phones
. But the operation cause an error:
// actually loads person from repository...
var person = _personRepository.Include(p => p.Phones).Where(p => p.Id == 1).First();
person.Phones.Clear();
_personRepository.Update(person);
您可以看到装上<代码>Person的简单逻辑,并填写<代码>Phones。 但出现这一错误:
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.
实际上,我想澄清所有<代码>Person.Phones,并增加一些新项目。 但我想在一个问题中予以澄清,不要逐一删除。
你们是否有任何想法? 您能否帮助我? 提前感谢。