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 3454172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:27:42+00:00 2026-05-18T09:27:42+00:00

I am trying to map classes User and Profile, just as the following: public

  • 0

I am trying to map classes User and Profile, just as the following:

public class User
{
    public long ID { get; set; }
    public string LoginName { get; set; }
    public Profile Profile { get; set; }
}

public class Profile
{
    //the ID is the same with User's ID 
    public long ID { get; protected set; }
    public string NickName { get; set; }
    public Gender Gender { get; set; }
}

So, they can be mapped as both one-to-one and componenet relationship. And I find some people appraise the component and think one-to-one is a bad practise, why? For performance reason? But they are designed as two separate tables in many scenarios(asp.net2.0 Membership, for example).

How should I choose? Which aspects should I consider? I know component means “value object” but not an enitity, but does this mean some further things?

ps: And what confused me more is the opinion that the many-to-one should be used even it’s one-to-one relationship in real world!

  • 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-18T09:27:42+00:00Added an answer on May 18, 2026 at 9:27 am

    You should use neither.

    One-To-One

    You have the user and the profile in different database tables but both share a mutually exclusive PK:
    See http://jagregory.com/writings/i-think-you-mean-a-many-to-one-sir/

    Pretty bad design practice for relational databases, it’s messy and does not necessarily enforce constraints for the relationship.

    Component

    You can use component to get a clean Object-Model from a messy relational database, profile and user data are both stored in the same database table but they should be separated in your object model (like you want it, judging from your code). Lazy loading probably isn’t supported, which will cause high database traffic.

    Reference

    Imho, you should use a Reference. It’s conceptual kinda like one-to-one but a user references a profile. The profiles can be stored in their own table, can be loaded lazily (performance) and are not dependent on a user.

    Regarding your confusion:
    Just read the link I supplied. Technically, you need a many to one for a properly designed database-scheme, as that is what is technically possible and will be mapped. I know it’s confusing. If you just need to map one-side, think of a reference instead of a one-to-one.

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

Sidebar

Related Questions

Using the following classes.. public class Trait { public virtual int Id { get;
I'm trying to map a Dictionary containing Lists. I have the following set of
Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many
Trying to map the following schema using the Entity Framework. A Customer can have
I have two tables (tbArea, tbPost) that relate to the following classes. class Area
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.
Before I was trying to map my classes and namespaces, by using static calls
So I have this two classes: public class PhysicalTest { public int ID {
I am trying to test out Mybatis's user manual with the result map section.
I'm working with an open source database. I'm trying to map it to classes

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.