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

The Archive Base Latest Questions

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

For reasons beyond my control I cannot use a real ORM, so I am

  • 0

For reasons beyond my control I cannot use a real ORM, so I am forced to create a custom DAL that sits over the raw data and returns “domain objects” to the consumer. Also for reasons beyond my control I must use Stored Procedures for data access.

I am making use of the Factory and Repository patterns for data access, or at least in basic theory:

  1. The call to SqlCommand and friends is hidden by a Repository class that takes parameters as needed and returns domain objects.
  2. To create the domain object, the Repository has an internal reference to a Factory of it’s own type (e.g. Customer, Order, etc.). The factory has a single method, Create, which takes a DataRow as its input and maps the DataRow’s columns to properties of the domain object.

This seems to work fairly well for basic objects that map to a single table. Now, here’s the issue I’m running into: I want some of these domain objects to be richer and have collections of related objects. Here’s a concrete example of a domain object in this system I’m working on:

class Case
{
    public string CaseNumber { get; internal set; }
    public ICollection<Message> Messages { get; set; }
}

class Message
{
    public int MessageId { get; internal set; }
    public string Content { get; set; }
}

In simple parlance, Case has many Messages. My concern is the best way to retrieve the raw data for a Case, since I also need a list of associated messages. It seems to me I can either:

  1. Run a second stored procedure in the CaseRepository when I retrieve a Case to get all the Messages that belong to it – this doesn’t seem like a good idea because it means every time I look up a Case, I’m making two database calls instead of one.
  2. Use one stored procedure that returns two tables (One containing a single row with information for the Case, one containing zero or more rows with messages that belong to it) and calling two factory methods i.e. CaseFactory.Create(caseDataRow) and a loop that calls MessageFactory.Create(messageDataRow). This makes more sense as the Case is the aggregate root (or pretending to be one as the case may be) so should know how to create messages that hang off of it.

The second option seems better performance but more code. Is there a third option I’m overlooking or is #2 the best way to handle this kind of composite object when I can’t use a true ORM (or even something like Linq to SQL)

  • 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-26T00:03:51+00:00Added an answer on May 26, 2026 at 12:03 am

    As it stands, your repositories are more like table gateways (even via sprocs). You’ll need a new layer of repositories, which have access to one or more table gateways, and are able to assemble the composite domain entities from the data returned from many tables.

    class Customer
    {
        string name; // etc
        Address homeAddress;
        Order[] orders;
    }
    
    interface ICustomerTableGateway { ... }
    
    interface IAddressTableGateway { ... }
    
    interface IOrderTableGateway { ... }
    
    class CustomerRepository
    {
        Customer Get(int id)
        {
            customer = customerTableGateway.Get(id);
            customer.Address = addressTableGateway.Get(customer.id);
            customer.Orders = orderTableGateway.GetAll(customer.id);
        }
    }
    

    If you can return multiple tables from the single sproc than that simplifies things further 🙂

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

Sidebar

Related Questions

For reasons beyond my control, I'm being tasked with Ruby web development that does
For reasons that are beyond my control I need to store huge arrays (10000+
For reasons that only the developers can understand, Firefox will create and open .url
For reasons beyond my control, I need to join two tables and I need
For reasons beyond my control, an app I am working on deploying needs to
I have a column in my oracle database which due reasons beyond my control
Due to reasons beyond my control (them being a DB of another system whose
For reasons beyond my control, I am currently working on a series of flash
For reasons beyond my control I am using PHP4 to write a twitter client.
apparently it works Can you name reasons beyond good practices not to give these

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.