[英]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.