一对多实体框架更新

时间:2017-06-19 17:32:41

标签: c# asp.net-mvc entity-framework

我有一个场景,我有一份包含员工详细信息的注册表。在这些数据中,我将员工联系人保存在另一个名为ContactMaster的表中,其余数据保存在EmployeeMaster中。我在EmployeeMaster中有一个外键作为ContactId。如何使用实体框架更新我的注册表单。我的类实体类如下。

public partial class ContactMaster
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public ContactMaster()
        {
            this.BranchMasters = new HashSet<BranchMaster>();
            this.EmployeeMasters = new HashSet<EmployeeMaster>();
        }

        public int Id { get; set; }
        public string TelephoneNumber1 { get; set; }
        public string TelephoneNumber2 { get; set; }
        public string Mobilenumber1 { get; set; }
        public string MobileNumber2 { get; set; }
        public string EmailId { get; set; }
        public string FaxNumber1 { get; set; }
        public string FaxNumber2 { get; set; }
        public string WebSite { get; set; }

        public virtual ICollection<EmployeeMaster> EmployeeMasters { get; set; }
    }

和EmployeeMaster如下。

 public partial class EmployeeMaster
    {
        public int Id { get; set; }
        public int BranchId { get; set; }
        public string Title { get; set; }
        public string Surname { get; set; }
        public string Firstname { get; set; }
        public System.DateTime DateOfBirth { get; set; }
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set; }
        public string AddressLine3 { get; set; }
        public string Town { get; set; }
        public string Country { get; set; }
        public string PostalCode { get; set; }
        public int ContactId { get; set; }
        public string PassportNumber { get; set; }
        public string PassportIssuedCountry { get; set; }
        public System.DateTime PassportExpiryDate { get; set; }
        public string VisaNumber { get; set; }
        public Nullable<System.DateTime> VisaExpiryDate { get; set; }
        public int JobRoleId { get; set; }
        public int BandId { get; set; }
        public string ChargeValue { get; set; }
        public int DepartmentId { get; set; }
        public int StatusId { get; set; }
        public Nullable<bool> IsDeleted { get; set; }


        public virtual ContactMaster ContactMaster { get; set; }
    }

0 个答案:

没有答案