繁体   English   中英

EF4.1代码第一个问题

[英]EF4.1 Code First Question

我想使用EF 4.1代码优先模型创建我的第一个应用程序。 我想为杂志订阅建模,但只想检查我的POCO类是否适合目的。

以下是我的课程。 我有什么想念的吗?

客户应该是订阅的成员还是仅仅是列表成为客户的成员?

谢谢。

public class Subscription
{
    public int SubscriptionID { get; set; }
    public string CardNumber { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public decimal NetPrice { get; set; }
    public decimal Tax { get; set; }
    public decimal Discount { get; set; }
    public string PromotionalCode { get; set; }
    public Customer Customer{ get; set; }
}

public class Customer    {
    public int CustomerID { get; set; }
    public string Title { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public PostalAddress PostalAddress { get; set; }
    public string EmailAddress { get; set; }
    public string Telephone { get; set; }
    public string Mobile { get; set; }
    public DateTime DateOfBirth { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string SecurityQuestion { get; set; }
    public string SecurityAnswer { get; set; }
    public bool Valid { get; set; }
    public IList<Subscription> Subscriptions { get; set; }
    public bool MailMarketing { get; set; }
    public bool PartnerMailMarketing { get; set; }
}

public class PostalAddress
{
    public int ID { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string Address3 { get; set; }
    public string City { get; set; }
    public string Postcode { get; set; }
    public string Region { get; set; }
    public string Country { get; set; }
}

如果客户有X个预订,则每个预订都应有一个customerID,因此您需要在自己的Suscription类中使用它(公开int CustomerID {get; set;})。

OTOH,我认为您必须将该客户引用作为虚拟引用并将其作为订正引用(我不知道为什么)。

也许我错了,但这对我有用。

反正你怎么了

您的模型看起来正确。 您不一定需要Subscription类中的Customer属性,但是如果您要检索特定的Subscription然后想要查找与该订阅相关的客户,则确实有帮助。 在这种情况下,您可以执行var customer = mySub.Customer而不用查询具有特定订阅ID的客户。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM