实体框架“需要字段”错误但在debuuging中工作正常

时间:2016-07-11 08:48:45

标签: entity-framework debugging lazy-loading required-field

当我尝试更新使用某些虚拟(延迟加载)属性的实体时,我在entityframework中遇到了一个奇怪的错误。我从数据库中检索实体并更改其中的一对一属性,然后尝试再次更新它。某些虚拟属性的例外是该字段是必需的,而其他人没有此错误。 让一切变得更奇怪的是,当我尝试在调试模式下检查实体时,代码工作正常,我根本不会遇到任何错误。 还有其他人经历过这种行为吗?

由于

以下是代码:

public class IndependenceCheck : ModelBase
{
        [Key]
        public int IndependenceCheckID { get; set; }

        public int PrincipalCompanyID { get; set; }

        [Required]
        [ForeignKey("PrincipalCompanyID")]
        public virtual Company PrincipalCompany { get; set; }

        [ForeignKey("OrganizationAddressID")]
        [Required]
        public virtual Address OrganizationAddress { get; set; }

}

模型中有更多字段,而我尝试更新PrincipalCompany时没有出现错误,但对于OrganizationAddress,我得到了必需的字段错误。

0 个答案:

没有答案