[英]Web Application Class Design Advice?
我的Web應用程序將包含一些人員信息。 基本上在我的數據庫中,我將擁有諸如
personid autoid clubid personalinfoid
fname carmodel clubname personid
mname cartype clubaddress height
lname carcolor ethnicity
address license# driverslicense#
address2 boattype
homephone boatsize
cellphone
我不擔心表格設計只是為了舉例。
編輯了我的問題,以使其更加清楚。 您將如何設計這種性質的Web應用程序的類。 每個表格都應該有單獨的類嗎?
我想到的是創建一個包含所有字段的屬性類,並且屬性從db獲取和設置所有內容。 然后創建一個person.cs,auto.cs,personinfo.cs和clubs.cs類是這樣做的正確方法嗎?
您所建議的是有道理的,並且是對象數據庫框架的功能!
例如,如果您使用的是Entity Framewor k,則可以先創建類(想象中稱為“代碼優先”),然后EF將為您生成數據庫。 同樣,您可以“首先執行數據庫”並創建數據庫架構,然后EF將為您生成類。 就我個人而言,我更喜歡前者,因為它使您可以更好地控制數據庫版本。
還有很多其他可用的框架,這只是一個示例。
因此,使用EF,您的PersonalInfo
對象將如下所示:
public class PersonalInfo
{
public int Id { get; set; } //EF will automatically figure out this is your PK
public double Height { get; set; }
public string Ethnicity { get; set; }
public string DriversLicence { get; set; }
//EF automatically figures out that the PersonId property refers to your Person table
public int PersonId { get; set; }
public virtual Person Person { get; set; } //navigation property so you can do personalInfo.Person.FirstName
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.