Your address class should be annotated with the ComplexType
attribute and you'd need to explicitly map the column names:
[ComplexType]
public class Address
{
[Column("street")]
public string Street {get; set;}
// Other properties
}
質問
I have a class customer that contains address properties, phone properties and fax properties, but I want to take off the address, phone properties to complex types. Does properties are already in the database as columns.
[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; }
}
how to refactor this into:
[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; }
}
without conflicting with what already exist in the database?
解決
Your address class should be annotated with the ComplexType
attribute and you'd need to explicitly map the column names:
[ComplexType]
public class Address
{
[Column("street")]
public string Street {get; set;}
// Other properties
}