简体   繁体   中英

Web Application Class Design Advice?

My web application is going to consist of some people information. Basically in my database I will have fields such as

personid              autoid               clubid              personalinfoid
fname                 carmodel             clubname            personid 
mname                 cartype              clubaddress         height
lname                 carcolor                                 ethnicity
address               license#                                 driverslicense#
address2              boattype                                 
homephone             boatsize
cellphone

I am not worried about the table design just did this for an example.

Edited my question to try to make it more clear. How would you approach designing classes for a web application of this nature. Should I have separate classes for each table?

What I had in mind was to create a properties class that holds all the fields and properties gets and sets everything from the db. Then creating a person.cs, auto.cs, personinfo.cs, and clubs.cs classes would this be the right way to do this?

What you have suggested makes sense and is what Object to Database frameworks do!

If you were using Entity Framewor k for example, you could create you classes first (imaginatively called "code first") and then EF would generate the database for you. Equally you could do "database first" and create you database schema then EF will generate the classes for you. Personally I prefer the former as it gives you a bit more control with database versioning.

There are a plethora of other frameworks available and this is just one example.

So your PersonalInfo object would look something like this using EF:

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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