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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:18:23+00:00 2026-06-07T07:18:23+00:00

I have a 2 classes: Employee EmployeeDetails I have methods like this for Employee

  • 0

I have a 2 classes:

  • Employee
  • EmployeeDetails

I have methods like this for Employee class:

public static Employee LoadEmployee(int id)
{
    StringBuilder selectQuery = new StringBuilder();

    string selectQuery = " my query with the parameter 'Id' ";
    dbGenerator _db = dbGenerator.Instance.Database;

    DbCommand selectCommand = _db.GetSqlStringCommand(selectQuery.ToString());
    _db.AddInParameter(selectCommand, "@id", System.Data.DbType.String, Id);

    //EXECUTE THE COMMAND
    using (IDataReader dr = _db.ExecuteReader(selectCommand))
    {
        if (dr.Read())
        {
            result = new Employee();
            Employee.LoadDataReader(result, dr);
        }

        dr.Close();
    }

    return result;
}

And I have a method doing the same thing with the EmployeeDetails class … no change at all except the return type.

I am sure there are ways to minimize the lines of code and also using the C# generics it will more readable and generics provide type safety without the overhead of multiple implementations.

I need a method in which I can pass the class object, selectQuery, ParameterId like this

public static <T> LoadData<T>(Object object, string selectQuery, int paramId)
{
    // do stuff 

    // return <T>results;
}

Any suggestion would be appreciated.

  • 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-06-07T07:18:25+00:00Added an answer on June 7, 2026 at 7:18 am

    The others’ suggestions of just using an ORM are great, but if you have a good reason for doing this layer from scratch, you could amend your design to look something like this:

    public class Employee 
    {
        public virtual void InitFromDataReader(DataReader dr) { }
    }
    
    public class EmployeeDetails : Employee
    {
        public override void InitFromDataReader(DataReader dr) { }
    }
    
    public static TEmployee LoadEmployee<TEmployee>(int id) where TEmployee : Employee, new()
    {
        using (DataReader dr = new DataReader()) 
        {
            var result = new TEmployee();
            result.InitFromDataReader(dr);
            return result;
        }
    }
    

    The main constraint is that you need to have a no-args constructor on your entity objects, otherwise the LoadEmployee methods can’t create them correctly. That is, unless you explicitly pass a factory object as a parameter to the method.

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

Sidebar

Related Questions

If I have a couple of classes like this ; public class Employee {
I have classes structured like this: Public MustInherit Class A ' several properties End
Say I have several ObservableCollections of different classes: public class Employee { public int
I have two classes Address and Employee as follows: public class Address { public
As a simplified example, I have the following data classes: public class Employee {
I have 3 classes, two inherit from 1: public class Employee { private virtual
I have two classes class Deptartment{ int deptid, String deptname; List<Employee> employees; } class
I have the following classes public class Person { public virtual int Id {
I have the following classes public class Person { public virtual int Id {
first things first. I have the following classes: class Employee { private int employeeID;

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.