EF6 Code First Relationship(MVC 5 app)

时间:2014-09-15 15:38:56

标签: entity-framework relational-database

我有以下课程

public class Address
    {

        public int ID { get; set; }
        public AddressType AddressType { get; set; } // (  Enum -- {Correspondence, Billing, Other}
        public string AddressLine {get; set;}               
        public string Town {get; set;}                       
        public string Region {get; set;}                   
        public string PostCode { get; set; }               
        public string Country {get; set;}

    }
}

 public class Company
    {
        [Key]
        public int ID { get; set; }
        public string LegalName { get; set; }
        public string RegistrationNumber { get; set; }

        public List<Address> Addresses { get; set; } // Addresses (Correspondence, billing address,physicalAddress etc)

}


public class Person
    {
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
        public List<Address> Addresses { get; set; }

    }

 public ActionResult AddCompany()
        {
            Company Co = new Company();
            Address postAddress = new Address() { AddressType = Helper.Enums.AddressType.PostAddress };
            Address physicalAddress = new Address() { AddressType = Helper.Enums.AddressType.PhysicalAddress };
            org.Addresses = new List<Address>();
            org.Addresses.Add(postAddress);
            org.Addresses.Add(physicalAddress);
}

我希望在添加Person或Company时添加Address,但不能使用Seed方法添加。

EF在地址表中创建CompanyID为什么,我只希望单向关系,请帮助

0 个答案:

没有答案