1

In my application, a user can choose between 3 profiles to created.

For now, I have 3 tables in the database representing the profiles. One table for each profile.

But I don't know how to work with this In a proper way In the code.

Let say that I visit a profile by entering the following URL:

mysite.com/fishness

Either to get data from the database that belongs to the "fishness" profile, I must search In three tables. How should I do the search? Should I just do three querys for each table? Or Is It a nicer way to do this?

Another thing Is when the user logs In. How should I get the profile that belongs to the user who logs in? Should I have navigation properties In my AppUser model( the model for the user )?

The ugly thing In my opinion about this, Is that I must then add navigation properties for all three profiles In my AppUser.

Can anyone give me tips about how to design this?

Here Is my three profile tables:

Profile1:

Id
UserId (the users Id)
Name
CoverPicture
Description
WelcomePage

Profile2:

Id
UserId (the users Id)
Name
CoverPicture
Description
WelcomePage

Profile3:

Id
UserId
Firstname
Lastname
Birth
Profilepicture
WelcomePage
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
Bryan
  • 3,421
  • 8
  • 37
  • 77

3 Answers3

0

You design is not good because it is not scallable , imagine you want to create a new profile , you will be obliged to create new table and edit your code .

My suggestion is to create a table profile and user , user has a column profileId that reference profile column id (foreign key) .

Table profile
ProfileID 
ProfileDesignation

Table user
UserId
Firstname
Lastname
Birth
Profilepicture
CoverPicture
Description
WelcomePage
ProfileID references profile.ProfileID
0

Your question appears to be a classic case of "how do I implement inheritance in my database". There are several similar questions on SO; the best answer is here.

As far as I understand, you have 3 types of profile. They each share some attributes (ID, UserID and WelcomePage), but each type may have attributes that are not shared (profile 1 and profile 2 look the same to me). That's a classic inheritance scenario.

There is no clean implementation in the relational model for this situation; instead, you must make trade-offs. Your current design is "table per concrete", and is perfectly reasonable.

Community
  • 1
  • 1
Neville Kuyt
  • 29,247
  • 1
  • 37
  • 52
0

I created two sample table AppUser and UserProfile.Both tables are linked with foreign key AppuserId which is Primary key for Appuser. enter image description here

If you want to create model for user Profile you can create separate classes per each table.when user login based on AppuserId you can access profile information.

user3824027
  • 440
  • 3
  • 10