Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:05:16+00:00 2026-05-20T11:05:16+00:00

I have a question that must be answer several times before, but I can’t

  • 0

I have a question that must be answer several times before, but I can’t find any good search words to find out what’s the best approach to solve it.

In my application I will have different types of Users, that will have different properties and different methods, but much of it will also be the same. So I create a baseclass ‘User’ and the other classes ‘Player’, ‘trainer’ and so on… that inherits from the ‘User’ class.

How should I save this in the database, in one huge table called ‘User’ that has all different properties from all classes, or should my database look like my classes? I think solution 2 is better.

I will only have one login method, so it will always return the baseclass, but then when the different specific types (‘player’,’trainer’) should be use there will be a cast to that class. But how I do the database call to populate my different classes.

What I could do is that in the user-table the type is also saved. When I get that information back to my code, I check what the type is and then call to the database getting the specific information for that type, create the correct type and return it as a ‘user’ in the code. But I don’t like the idea that I need to call twice to the database to fill my objects with data, I could solve it with a SP, but I try not to use SP’s.

Is there a good way to solve this with one call to the database, when I don’t know what type that will be returned when I call to database.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:05:17+00:00Added an answer on May 20, 2026 at 11:05 am

    First of all, in my opinion, I’d like to suggest you to don’t think a relational design based on the object-oriented software solution on top of it.

    Taking last sentence as true, my hint will be each type of entity that has something to do in the business, you’ll design a data table for it.

    Anyway, I find you could have another relational design. Why don’t you create such “Users” table which has basic information like an unique identifier, credentials – and any other basic info you would need for user identification, authentication and authorization -?

    Having this, you’d design a relational table called “TrainerUsersProfiles”, “PlayerUsersProfiles” and so on.

    In fact, “TrainerUsersProfiles”, “PlayerUsersProfiles” is something like a profile data, because you’ve to be an user in order to authenticate and be authorized to application’s resources. But an user can have more related information, say it a “profile”. Any information as a trainer or player is part of user’s profile.

    Now is time to find which attributes are shared on trainers and players (and any other one). Such shared attributes should be in user’s profile table “UsersProfiles” which has an one-to-one relation to an specific user.

    In instance, I’d put any extended profile data in “TrainerUsersProfiles” and “PlayerUsersProfiles”, and both (or more) would have a one-to-one relation to some user profile.

    Summarizing: An user has a profile, and a profile has an extended, specialized profile data.

    Talking about object-oriented layer – the application -, I’d like to suggest it’d better to avoid that abstract factory and just use a repository:

    userRepository.GetById([id])
    

    User class would have a “Kind” property, which is an enumeration of user profile kinds (Trainer, Player, and so on).

    In addition, User class would have a “Profile” property, which should have a “Properties” property itself too. “Properties” is of a type called like “ProfileProperties” and there’s a “TrainerProperties” and “PlayerProperties” deriving it.

    Finally, this would be some sample usage:

    User someUser = userRepository.GetById([id]);
    string somePropertyValue = null;
    
    switch(someUser.Kind)
    {
        case Trainer:
                somePropertyValue = ((TrainerProperties)someUser.Profile.Properties).SomeTrainerProperty;
                break;
        case Player:
                somePropertyValue = ((PlayerProperties)someUser.Profile.Properties).SomePlayerProperty;
                break;
    }
    

    I believe this could be your right solution and it can end in a good relational and object-oriented design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question, the answer isn't really hard technically, but I am more
Question: I have a question that is apparently not answered by this already-asked Bash
I am learning LINQ and have a very simple question that I think will
I have a question with fluent interfaces. We have some objects that are used
So I'm learning java, and I have a question. It seems that the types
Question We have a large number of xml configuration files that we want merged
From a previous question I have seen that the CLR has workstation and server
Another basic Rails question: I have a database table that needs to contain references
This is a (hopefully) really simple question - I have been told recently that
Question Is there a way to have a method that will always run anytime

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.