2012-04-24 78 views
0

我正在創建一個應用程序,其中使用實體框架使用代碼優先。我創建了一些模型,但在我進一步去之前,我想驗證一些東西。我創建的模型用於產品,客戶和訂單等。我也創建了一些我用作類型的模型,比如地址。例如:在C#模型中使用複雜類型與單獨屬性

public class Customer 
{ 
    public int CustomerID { get; set; } 
    public string CustomerName { get; set; } 
    public string CustomerEmail { get; set; } 
    public string PhoneNumber { get; set; } 
    public Address ShippingAddress { get; set; } 
    public Address BillingAddress { get; set; } 
} 

public class Address 
{ 
    public string AddressLineOne { get; set; } 
    public string AddressLineTwo { get; set; } 
    public string Company { get; set; } 
    public string City { get; set; } 
    public string State { get; set; } 
    public int ZipCode { get; set; } 
    public string Country { get; set; } 
} 

是否優先於創建ShipToAddress,ShipToState等單個屬性?我對網絡開發非常陌生,不想因爲這些問題而導致一些問題而不得不開始這一切。感謝您提前給予幫助,如果我不夠清楚,我會提前道歉。

回答

1

是更好的方法,然後爲ShipToState創建單獨的屬性等。這樣您就可以將Address類與其他類一起使用。

+0

太棒了!感謝您的快速回復。請注意,我應該將地址類等模型與文件結構中的所有其他實體一起保存,還是應該有自己的文件夾? – IanAuld 2012-04-24 21:07:28

+0

我會讓他們在與其他實體相同的文件夾 – Habib 2012-04-25 02:30:08

+0

感謝您的幫助。 – IanAuld 2012-04-25 18:05:16