【发布时间】:2013-10-16 15:52:44
【问题描述】:
我有这个模型(动物模型):
public int Id { get; set; }
public int AnimalSpecieId { get; set; }
public int AnimalBreedId { get; set; }
public Nullable<int> ProtectorId { get; set; }
public Nullable<int> OwnerId { get; set; }
public string Name { get; set; }
public virtual Owner Owner { get; set; }
public virtual Protector Protector { get; set; }
保护器型号:
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string CellPhone { get; set; }
public string Email { get; set; }
public virtual ICollection<Animal> Animals { get; set; }
所有者模型:
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string CellPhone { get; set; }
public string Email { get; set; }
public virtual ICollection<Animal> Animals { get; set; }
当我第一次插入这个模型时,如果
保护者 ID = 1
和
OwnerID = null
没关系,但是,我尝试更新这个模型,改为:
所有者 ID = 1
和
ProtectorID = null
我在标题中遇到错误,有人可以帮助我吗?
【问题讨论】:
-
您也可以发布保护者和所有者实体吗?通常,当有一个属性引用回(在这种情况下)Animal 模型时,就会发生此错误。还要确保存在 ID 为 1 的所有者。
-
更新了 Protector 和 Owner 模型。
-
我暂时是空白的.. :|
标签: c# entity-framework entity-framework-5