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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:45:56+00:00 2026-05-25T02:45:56+00:00

For one to one relationships things are easy. When it comes to one to

  • 0

For one to one relationships things are easy.
When it comes to one to many or many to many problems appear…
I am not using an ORM tool now for many reasons and i am wondering when i want to get data whether it is better to reassemble one to many relationship using multiple queries or in code..

For example.. Having a class Category and a class Product…

A product table has a collumn for category id (one category many products).

So for my full catalog is it better to execute 2 queries to get the categories and products i want and then populate for each category its products List ? (It is very easy with LINQ) ..

Or i should call query for each category ? Like select id from products where category_id=5;

Also i dont know how to name the functions like to set whether i want to fetch the other side of the relationship or not..

  • 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-25T02:45:57+00:00Added an answer on May 25, 2026 at 2:45 am

    If you want to retrieve all categories and all their products, you can either select all categories and then select all products in two queries, or you can select in one query and group.

    To use just one query, select an inner join for your two tables

    SELECT c.*, p.* 
    FROM Category c INNER JOIN Product p ON c.CategoryId = p.CategoryId
    

    and then construct business objects from the resulting dataset

    result.GroupBy(r => r.CategoryId).Select(group =>
        new Category(/* new Category using c.* columns */)
        { 
            Products = /* new list of Products from p.* values */
        });
    

    But I have to ask – why aren’t you using an ORM?

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

Sidebar

Related Questions

I've seen people use many-to-one mappings to represent one-to-one relationships. I've also read this
I have a table which has several one to many relationships with other tables.
I have a few model classes with basic one-to-many relationships. For example, a book
I have a case where i have three entities with one-to-many and one-to-many relationships:
I'm using the admin interface to view invoices and products. To make things easy,
One of the things I come across in databases now and then is a
I understand how to design a database schema that has simple one-to-many relationships between
One of the reasons why referential integrity should not be enforced is performance. Because
Is there a way to check CakePHP's model relationships? One model is saving twice
The problem: Maintain a bidirectional many-to-one relationship among java objects. Something like the Google/Commons

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.