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

  • Home
  • SEARCH
  • 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 6934867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:01:05+00:00 2026-05-27T12:01:05+00:00

Say I have a User object, which is generated by a Usermapper . The

  • 0

Say I have a User object, which is generated by a Usermapper. The User object does not know anything about the database/repository in use (which I believe to be good design).

When creating a User, I only want it to have it filled by the mapper with the most trivial things e.g. Name, address etc. However after object instantiation I might have a method userX.getTotalDebt(), getTotalDebt() would need to reconnect to the database , because I don’t want this relatively expensive operation to be done for every User instantiation (multiple tables needed etc). If I’d simply insert some sql in the getTotalDebt() or a dependency back to the Mapper where the coupledness is growing tight very fast.

There is an obvious good/best practice for this, because it’s a situation arises often, however I can’t find it or I’m looking at this problem totally from a wrong angle.

  • 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-27T12:01:05+00:00Added an answer on May 27, 2026 at 12:01 pm

    Say I have a User object, which is generated by a Usermapper. The User object does not know anything about the database/repository in use (which I believe to be good design).

    They are often referred to as POCOs (Plain Old CLR Objects).

    When creating a User I only want it to have it filled by the mapper with the most trivial things e.g. Name, address etc.

    There are several OR/M layers which can achieve this. Use either nhibernate or Entity Framework 4.1 Code First.

    I might have a method userX.getTotalDebt(), getTotalDebt() would need to reconnect to the database

    Then it’s not a poco anymore. Although it is possible using a transparent proxy. Both EF and nhibernate supports this and it’s called Lazy Loading.

    There is an obvious good/best practice for this, because it’s a situation arises often, however I can’t find it or I’m looking at this problem totally from a wrong angle

    I usually keep my objects dumb and disconnected. I use the Repository pattern (even if I use nhibernate or another orm) since it makes my classes testable.

    I either use the repository classes directly or create a service class which contains all logic. It depends on how complex my application is.

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

Sidebar

Related Questions

When creating a web application, and lets say you have a User object denoting
If I have an object say @user and I want to render only certain
Let's say I have a user that entered 12 links into the database but
I have a user control - say ControlBase. It has SomeItems property, which is
Let's say I have a domain class called User which can follow other User
Lets say I have object Tom which has class Person. Class Person String Name
I have a user object represented in JPA which has specific sub-types. Eg, think
Say I have an object called data which contains a variety of information. Let's
Let's say I have definied a User object using GORM. Each user can have
Let's say I have two objects: User and Race. class User attr_accessor :first_name attr_accessor

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.