微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

EF4.1代码第一个问题

如何解决EF4.1代码第一个问题

| 我想使用EF 4.1 Code First Model创建我的第一个应用程序。我想为杂志订阅建模,但只想检查我的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的客户。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。