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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:01:52+00:00 2026-05-31T11:01:52+00:00

Some context: This pertains to my budding desire to build multilayer web applications with:

  • 0

Some context: This pertains to my budding desire to build multilayer web applications with:

  1. C# ASP.NET web forms
  2. C# POCO business objects
  3. Some kind of DAL… SQL (or maybe EF4 if I can figure it out)

I wouldn’t really want a response which has my presentation layer talking directly to EF entities, for instance.

I’ve been doing my own web development with C# ASP.NET & SQL for 10 years but I am still a total rookie when it comes to formal OOAD. I’ve been pursuing this skill with a passion lately, but I’m still new at it and there is something I can’t quite wrap my head around. I’m hoping someone can explain it in a way that brings an epiphany:

Let’s say I create a web application that manages People in some way, and my Person object must possess a properties such as FirstName, LastName, HairColor, EyeColor, Ethnicity, StateOrProvince, etc. I’m using SQL Server for persistence… so common sense would dictate that the respective fields in the People table are all foreign keys:

FirstName varchar(50)
LastName varchar(50)
HairColor tinyint
EyeColor tinyint
Ethnicity tinyint
StateOrProvince tinyint

Clearly this means that I have corresponding lookup tables for each of those fields (i.e. HairColors table, EyeColors table, Ethnicities table, etc.) and each of these lookup tables has an ID and a name. Of course the Name field in these lookup tables will be JOINed with my People data whenever I want to display anything useful about a Person.

Some key features of the site would be:

1.) Enumerate People in a Gridview (FirstName, LastName, HairColor, EyeColor, Ethnicity, StateOrProvince)

2.) Show an individual Person’s details on a read-only page (FirstName, LastName, HairColor, EyeColor, Ethnicity, StateOrProvince)

3.) Allow a user to update an individual Person’s data on an update page (FirstName, LastName, HairColor, EyeColor, Ethnicity, StateOrProvince)

Case #1
If I was enumerating a collection of Person objects in a gridview… each Person instance would need to display its HairColor, EyeColor, Ethnicity, StateOrProvince properties as strings to be meaningful (i.e. the Name field from the SQL lookup table, not its ID). Clearly my SQL sproc would have some JOINs to give me the appropriate string data I need to fill these text properties in each Person instance.

Case #2
Again my sproc would have a JOIN to bring back the human readable property names as strings, and I would display them in read only Label controls using something like myPerson.HairColor, myPerson.EyeColor, etc.

Case #3
Here I’d be showing a page with dropdown lists for each of these properties (i.e. value=HairColorId, Text=HairColorName). My immediate instinct here would be to use the IDs of each property (something like myPerson.HairColorId) in order to loop through the DDL items and select a value which represents the hair color that the People table currently holds for this Person. If the user selected something different in any of the property DDLs, I’d need to pass the appropriate SelectedId values to an UPDATE sproc, and modify the values in the People table for this particular Person.

So that leads me to the ultimate question:

How do I best design a Person object such that it contains both the ID and Name for HairColor, EyeColor, Ethnicity, StateOrProvince so I can subsequently use the Name when displaying information, but the ID for initializing the update DDL controls… and ultimately processing updates?

As I’ve reflected on this… I have come to the conclusion that I need to create classes to represent the HairColor, EyeColor, Ethnicity, StateOrProvince properties.

Then my Person class, instead of being something like this:

public class Person
{
    string FirstName { get; set; }
    string LastName { get; set; }

    int HairColorId { get; set; }
    string HairColorName { get; set; }

    int EyeColorId { get; set; }
    string EyeColorName { get; set; }

    int StateOrProvinceId { get; set; }
    string StateOrProvinceName { get; set; }
    string StateOrProvinceCode { get; set; }
}

Would instead be expanded into something like this:

public class HairColor
{
    int Id { get; set; }
    string Name { get; set; }
}

public class EyeColor
{
    int Id { get; set; }
    string Name { get; set; }
}

public class StateOrProvince
{
    int Id { get; set; }
    string Name { get; set; }
    string Code { get; set; }
}

public class Person
{
    HairColor HairColor { get; set; }
    EyeColor EyeColor { get; set; }
    StateOrProvince StateOrProvince { get; set; }

    public Person()
    {
        // how do I initialize a Person from a SQL data row?

    }
}

But then if my Person class does look like the above… how on earth do I best initialize it (whether individually or in a collection) from a given row of data I get back from a SQL query? I seem to recall that I shouldn’t be newing things up in a constructor (i.e. this.HairColor = new HairColor(dr[“HairColorId”), dr[“HairColorName”];)… so I’m wondering how a call to

public static IEnumerable<Person> GetPeople()
{
    ...
}

in my BLL might fill each user up with its data before it is added to the collection?

Really hoping someone can give me an “a ha” moment here…

  • 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-31T11:01:53+00:00Added an answer on May 31, 2026 at 11:01 am

    I think you have the right approach, creating classes for those supporting entities (although I’d put StateOrProvince in a separate Address entity, and maybe all those traits in a separate PersonTraits entity).

    There’re many ways to solve this. Without an ORM, take a look at Data Mappers (also at Dependent Mapping), which could be used to map from a database query to a Person instance. This is an outline of the mapper code:

    var row = ... // query database
    var person = new Person(row["FirstName"], row["LastName"]);
    person.EyeColor = new EyeColor(row["EyeColorID"], row["EyeColorName"]);
    ...
    

    (You could also use some kind of separate Object Builder.)

    Anytime you update a person, you update all supporting information as well using the ID of the related entities.

    UPDATE: an ORM like EF4 is very powerful and would help you with a lot of repetitive tasks (like the mapping I’ve described). The important thing is to keep your architecture flexible and have persistency as just one swappable layer. Take a look here for some guidance. Also, I found that the book “Domain Driven Design” is really important to understand this kind of separation and how to model your entities.

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

Sidebar

Related Questions

Just to put some context. ASP.NET MVC2 Web API 5 IIS 7 I am
Some context: one of the systems I'm working on is a .net 2.0 web
I'm using ASP.NET, but I'm sure this pertains to any (or most) MVC frameworks.
Context I came across some code, like this: if( Some_Condition ) throw 0; I
I have a web project using asp.net mvc3. Now clients ask for a security
First some context: I have an MVC3 .net project which, for the sake of
To put the question into some context, the system exposing the web service uses
I noticed some context menus in various tutorials on the web look different than
I have some content like this: author = Marjan Mernik and Viljem Zumer, title
I have a flex app which allows user to create some content. this content

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.