在C#模型中使用复杂类型与单个属性

时间:2012-04-24 20:49:51

标签: asp.net-mvc-3 entity-framework

我正在创建一个使用代码优先使用Entity框架的应用程序。我已经创建了一些模型,但在我再进一步之前,我想验证一些事情。我创建的模型适用于产品,客户和订单等。我也创建了一些我用作类型的模型,比如地址。例如:

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等个别属性更可取吗?我对Web开发很陌生,并且不希望因为这一问题导致的一些问题而不得不重新开始。如果我不够清楚,请提前感谢您的帮助,我提前道歉。

1 个答案:

答案 0 :(得分:1)

是的,它是更好的方法,然后为ShipToState等创建单独的属性。这样你就可以将Address类与其他类一起使用。