Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SqlException:不包含';不存在于溶液中_C#_Entity Framework - Fatal编程技术网

C# SqlException:不包含';不存在于溶液中

C# SqlException:不包含';不存在于溶液中,c#,entity-framework,C#,Entity Framework,我试图让实体框架与我构建的数据库一起工作,但我遇到了一个奇怪的错误,对我来说毫无意义 当我尝试运行我的程序时,我得到一个异常,并出现以下stacktrace: Unhandled Exception: System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for detai

我试图让实体框架与我构建的数据库一起工作,但我遇到了一个奇怪的错误,对我来说毫无意义

当我尝试运行我的程序时,我得到一个异常,并出现以下stacktrace:

Unhandled Exception: System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. 
See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'CorrespondenceAddress_AddressId'.
该程序听起来像是在试图查找列
对应地址\u AddressId
,当找不到时抛出异常。但是,在我的数据库中或解决方案中的代码中没有定义此列,因此我不知道从何处获取此列名

具有
通讯地址
属性的类是我的
属性
类。定义如下:

public partial class Property
    {
        private int _propertyId;
        private int _instructionId;
        private int _referenceNumber;
        private string _caseOwner;
        private int _amountBorrowed;
        private Address _securityAddress;
        private int _correspondenceAddressId;
        private int _securityAddressId;

        public Property()
        {
            Occupiers = new HashSet<Occupier>();
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Property(int propertyId, int instructionId, int reference, int amountBorrowed, JurisdictionTypes jurisdiction, FunderTypes funder,
                                bool correspondenceAddressIsSecurityAddress, Address correspondenceAddress, Address securityAddress)
        {
            Occupiers = new HashSet<Occupier>();

            PropertyId = propertyId;
            InstructionId = instructionId;
            ReferenceNumber = reference;
            CaseOwner = "";
            AmountBorrowed = amountBorrowed;
            Jurisdiction = jurisdiction;
            Funder = funder;
            CorrespondenceAddressIsSecurityAddress = correspondenceAddressIsSecurityAddress;
            SecurityAddress = securityAddress;
        }

        [Key]
        public int PropertyId
        {
            get => this._propertyId;
            set => this._propertyId = Math.Abs(value);
        }

        public int InstructionId
        {
            get => this._instructionId;
            set => this._instructionId = Math.Abs(value);
        }

        public int CorrespondenceAddressId
        {
            get => this._correspondenceAddressId;
            set => this._correspondenceAddressId = Math.Abs(value);
        }

        public int SecurityAddressId
        {
            get => this._securityAddressId;
            set => this._securityAddressId = Math.Abs(value);
        }

        public int ReferenceNumber
        {
            get => this._referenceNumber;
            set => this._referenceNumber = Math.Abs(value);
        }

        [StringLength(3)]
        public string CaseOwner
        {
            get => this._caseOwner;
            set => this._caseOwner = value.Trim();
        }

        public int AmountBorrowed
        {
            get => this._amountBorrowed;
            set => this._amountBorrowed = Math.Abs(value);
        }

        public TenureTypes Tenure { get; set; }

        public JurisdictionTypes Jurisdiction { get; set; }

        public FunderTypes Funder { get; set; }

        public bool CorrespondenceAddressIsSecurityAddress { get; set; }

        public virtual Address CorrespondenceAddress { get; set; }

        public virtual Address SecurityAddress
        {
            get => _securityAddress;
            set => _securityAddress = CorrespondenceAddressIsSecurityAddress ? null : value;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<Occupier> Occupiers { get; set; }

        public virtual SolicitorInstruction SolicitorInstruction { get; set; }
    }

有人能给我解释一下这个错误吗,因为我不知道如何修复它。

更改实体类和表中的通信地址ID和安全地址ID的顺序。错误消息现在是否更改为SecurityAddress\u AddressId

当事物没有隐式声明时,EF推断具有默认行为的事物。通讯地址\u AddressId是试图查找未声明的内容

您只声明了一个:

SolicitorInstruction SolicitorInstruction { get; set; }
但有3个FK可以进行律师指导。Ef能够让第一个为InstructionId工作,并猜测其他人

您在此处有解决方案的代码:

SolicitorInstruction SolicitorInstruction { get; set; }