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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:34:48+00:00 2026-05-15T03:34:48+00:00

Its probarbly a simple 3-tier problem. I just want to make sure we use

  • 0

Its probarbly a simple 3-tier problem. I just want to make sure we use the best practice for this and I am not that familiary with the structures yet.

We have the 3 tiers:

  • GUI: ASP.NET for Presentation-layer (first platform)
  • BAL: Business-layer will be handling the logic on a webserver in C#, so we both can use it for webforms/MVC + webservices
  • DAL: LINQ to SQL in the Data-layer, returning BusinessObjects not LINQ.
  • DB: The SQL will be Microsoft SQL-server/Express (havent decided yet).

Lets think of setup where we have a database of [Persons]. They can all have multiple [Address]es and we have a complete list of all [PostalCode] and corresponding citynames etc.

The deal is that we have joined a lot of details from other tables.

{Relations}/[tables]

  • [Person]:1 — N:{PersonAddress}:M — 1:[Address]
  • [Address]:N — 1:[PostalCode]

Now we want to build the DAL for Person. How should the PersonBO look and when does the joins occure?
Is it a business-layer problem to fetch all citynames and possible addressses pr. Person? or should the DAL complete all this before returning the PersonBO to the BAL ?

Class PersonBO 
{
    public int ID {get;set;}
    public string Name {get;set;}
    public List<AddressBO> {get;set;} // Question #1
} 

// Q1: do we retrieve the objects before returning the PersonBO and should it be an Array instead? or is this totally wrong for n-tier/3-tier??

Class AddressBO 
{
    public int ID {get;set;}
    public string StreetName {get;set;}
    public int PostalCode {get;set;} // Question #2
} 

// Q2: do we make the lookup or just leave the PostalCode for later lookup?

Can anyone explain in what order to pull which objects? Constructive criticism is very welcome. :o)

  • 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-15T03:34:49+00:00Added an answer on May 15, 2026 at 3:34 am

    You’re kind of reinventing the wheel; ORMs already solve most of this problem for you and you’re going to find it a little tricky to do yourself.

    The way ORMs like Linq to SQL, Entity Framework and NHibernate do this is a technique called lazy loading of associations (which can optionally be overriden with an eager load).

    When you pull up a Person, it does not load the Address until you specifically ask for it, at which point another round-trip to the database occurs (lazy load). You can also specify on a per-query basis that you want the Address to be loaded for every person (eager load).

    In a sense, with this question you are basically asking whether or not you should perform lazy or eager loads of the AddressBO for the PersonBO, and the answer is: neither. There isn’t one single approach that universally works. By default you should probably lazy load, so that you don’t do a whole lot of unnecessary joins; in order to pull this off, you’ll have to build your PersonBO with a lazy-loading mechanism that maintains some reference to the DAL. But you’ll still want to have the option to eager-load, which you’ll need to build into your “business-access” logic.

    Another option, if you need to return a highly-customized data set with specific properties populated from many different tables, is to not return a PersonBO at all, but instead use a Data Transfer Object (DTO). If you implement a default lazy-loading mechanism, you can sometimes substitute this as the eager-loading version.


    FYI, lazy loaders in data access frameworks are usually built with the loading logic in the association itself:

    public class PersonBO
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public IList<AddressBO> Addresses { get; set; }
    }
    

    This is just a POCO, the magic happens in the actual list implementation:

    // NOT A PRODUCTION-READY IMPLEMENTATION - DO NOT USE
    
    internal class LazyLoadList<T> : IList<T>
    {
        private IQueryable<T> query;
        private List<T> items;
    
        public LazyLoadList(IQueryable<T> query)
        {
            if (query == null)
                throw new ArgumentNullException("query");
            this.query = query;
        }
    
        private void Materialize()
        {
            if (items == null)
                items = query.ToList();
        }
    
        public void Add(T item)
        {
            Materialize();
            items.Add(item);
        }
    
        // Etc.
    }
    

    (This obviously isn’t production-grade, it’s just to demonstrate the technique; you start with a query and don’t materialize the actual list until you have to.)

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

Sidebar

Related Questions

Probably very simple question (I just want to ensure I'm right). Title is not
I know that this is probably a simple fix, but I have not been
Its been a long day and this is probably extemely simple but how do
Ok this is probably so simple that it's laughable, but I can't figure the
EDIT: Seems i didnt use an 'id' on my textarea, so that problem has
Im sure this is probably a simple answer, but I cannot see anything wrong
Probably a simple question, but I'm not that good with loading files… Getting my
I feel a little silly asking this, because its probably realy simple. Select DISTINCT
Hope you can help me with this its probably really simple but I'm pretty
The code for this is probably simple, but I'm not hot on Jquery yet

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.