我有一个班级客户,其中包含地址属性,电话属性和传真属性,但我想将地址,电话属性转换为复杂类型。属性是否已作为列存在于数据库中。
[Table("tblCustomer")]
public partial class Customer : Entity
{
[Key]
public int CustomerID { get; set; }
[StringLength(10)]
public string CustomerCode { get; set; }
[StringLength(60)]
public string AddressLine1 { get; set; }
[StringLength(70)]
public string AddressLine2 { get; set; }
[StringLength(35)]
public string City { get; set; }
[StringLength(2)]
public string State { get; set; }
[StringLength(10)]
public string ZipCode { get; set; }
[StringLength(15)]
public string PhoneNo { get; set; }
[StringLength(3)]
public string PCountryCode { get; set; }
[StringLength(3)]
public string PAreaCode { get; set; }
[StringLength(7)]
public string PPhoneNo { get; set; }
[StringLength(3)]
public string FCountryCode { get; set; }
[StringLength(3)]
public string FAreaCode { get; set; }
[StringLength(7)]
public string FaxNumber { get; set; }
[StringLength(3)]
public string CountryCode { get; set; }
}
如何将其重构为:
[Table("tblCustomer")]
public partial class Customer : Entity
{
[Key]
public int CustomerID { get; set; }
[StringLength(10)]
public string CustomerCode { get; set; }
public Address Address { get; set; }
public Phone Phone { get; set; }
public Phone Fax { get; set; }
}
与数据库中已存在的内容没有冲突?
答案 0 :(得分:0)
您的地址类应使用ComplexType
属性进行注释,并且您需要显式映射列名称:
[ComplexType]
public class Address
{
[Column("street")]
public string Street {get; set;}
// Other properties
}