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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:14:03+00:00 2026-05-26T08:14:03+00:00

Simple question I have a class say person who has as a property a

  • 0

Simple question
I have a class say person who has as a property a member of another class say Department.
In code terms:

class person {
public string fname {get; set;}
public string lname {get; set;}
public Department d {get; set;}
}

When I load a person I have my front end web site call my business object layer which then makes a call to my data acess layer, something to this effect:

website:
Person p;
p = BOL.GetPerson(1); //call function that returns a person

And in my business object layer I simply do some business logic and call the data access layer like so:

BOL:

return DAL.GetPerson(1); //returns a person from my Data access layer

Inside my DAL i’m simply calling a stored procedure which pulls this information from a person’s table. The only thing is I dont pull the department data because its a rather large structure…

So my question is how can i lazy load this department object in my get property WITHOUT my object knowing or calling the Business Object layer. In addition, i think it is bad practice to tightly couple a Department object with the BOL object.

In other words I DONT want to do this in my person class:

public Department d {
  get 
     {
      if(d==null)
           {
            d = BOL.GetDepartmentInfo();
           }
     }
  set 
       {
        //some code
        }

That is a person class should only contain relevant information about a person, so it really should not know about the Business object layer.

How can I solve this problem?

Edit

Here is the property:

public FunctionalGroup Department
{
    get
    {
        if (Department == null)
        {
            Department = GetDepartment();
        }
    }
    set
    {
        Department = value;
    }
}

public Action<FunctionalGroup> GetDepartment { private get; set; }

This complains that Delegate Action does not take 0 arguments

I tried calling it from the BOL like so:

//assume already have an employee object
 e.GetDepartment = (id) => BOL.GetFunctionalGroup(e.FunctionalGroupID);

Edit 2nd time

Basically here is what I have:

 private FunctionalGroup _d = null;

        public FunctionalGroup Department
        {
            get
            {
                if (_d == null)
                {
                    _d = GetDepartment();
                }
                return _d;
            }
            set
            {
                _d = value;
            }
        }

//        public Action<string, FunctionalGroup> GetDepartment { private get; set; }

        public Func<FunctionalGroup> GetDepartment { private get; set; }

My BOL class is trying to assign to this:

e.Department = (id) => BOL.GetFunctionalGroup(e.FunctionalGroupID);

My BOL class says:

public static FunctionalGroup GetFunctionalGroup(string fgID)
 {
  return DAL.GetFunctionalGroup(fgID);
 }

My DAL looks like this:

  /// <summary>
        /// Returns a functional group object along with all of its properties, otherwise null.
        /// </summary>
        /// <param name="fgID">String representation of a functional group (ex: "A-AD-C")</param>
        /// <returns>Functional group object with all associated properties, otherwise null.</returns>
        public static FunctionalGroup GetFunctionalGroup(string fgID)
        {
            FunctionalGroup fg = null;

            if (fgID.Length != 0)
            {
                  //connString = the string of our database app found in the resource file
                using (SqlConnection con = new SqlConnection(connString))
                {
                    using (SqlCommand cmd = new SqlCommand("EMPDLL_selFunctionalGroupByFunctionalGroupID", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@FunctionalGroupID", SqlDbType.VarChar).Value = fgID;
                        con.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                if (reader.Read())
                                {
                                    //found a func group
                                    fg = new FunctionalGroup((string)reader["FunctionalGroupID"],
                                                             (long)reader["ClientID"],
                                                             (string)reader["CostCenter"],
                                                             (string)reader["Description"],
                                                             (string)reader["Comments"],
                                                             (string)reader["AddedBy"],
                                                              reader["DateAdded"] == DBNull.Value ? null : (DateTime?)reader["DateAdded"],
                                                             (string)reader["ModifiedBy"],
                                                             reader["DateModified"] == DBNull.Value ? null : (DateTime?)reader["DateModified"],
                                                             (bool)reader["Inactive"]);
                                }
                            }
                        }
                    }
                }
            }
            return fg;
        }

Final Edit

Ended up using my BOl with this:

e.GetDepartment = () => BOL.GetFunctionalGroup(e.FunctionalGroupID);

And my employee class with this:

 private FunctionalGroup _d = null;

        public FunctionalGroup Department
        {
            get
            {
                if (_d == null)
                {
                    _d = GetDepartment();
                }
                return _d;
            }
            set
            {
                _d = value;
            }
        }

        public Func<FunctionalGroup> GetDepartment { private get; set; }
  • 1 1 Answer
  • 2 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-26T08:14:03+00:00Added an answer on May 26, 2026 at 8:14 am

    You can give the person object a callback method that can load the department for that person:

    class person {
    
      private Department _department = null;
    
      public Func<Department> GetDepartment { private get; set; }
    
      public string fname { get; set; }
      public string lname { get; set; }
    
      public Department d {
        get {
          if (_department == null) {
            _department = GetDepartment();
          }
          return _department;
        }
      }
    
    }
    

    When you get the person object in the business layer:

    p.GetDepartment = () => BOL.GetDepartment(1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question on best practice. Say I have: public class Product { public string
Fairly simple question: I have an init method on my class that has the
I have simple type Question : public class Question { public string[] Tags {
the question is simple. I have a base abstract class (person). From this i
Well, the question is kinda simple. I have a object defined as: public class
Let's say I have a simple class Cat in C#, with a Name property
Simple question : I have a service class (let's say helpersService ) and a
Let's say I have a simple parent->child class structure as shown below Public Class
This is a simple question (I think) Lets say I have this code (Assuming
Pretty simple question. I'm quite certain I have the Class, method, codebehind, etc linked

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.