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

  • Home
  • SEARCH
  • 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 9022311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:28:36+00:00 2026-06-16T05:28:36+00:00

I am using CoolStorage as an ORM and have a question regarding how often

  • 0

I am using CoolStorage as an ORM and have a question regarding how often the database is being queried.

I am returning a list of teams, and also want to display the number of users contained within each team. I am returning the teams by calling Team.List() and there are 2 options I can think of how to return the number of users. One is by adding a property to the Team class which returns a count of its [OneToMany] SysUsers, and the other is to use LINQ on the result returned by Team.List(). The code below demonstrates both methods, both of which return the same result.

I am trying to understand how this affects database interaction, for example will it first return a list of Teams, and then run a separate query against each one to get the number of users? If I then wanted to add another 2 or 3 fields would it then run another separate query for each additional field? Is there any difference between the two approaches?

My concern is that if the connection isn’t great this could make even simple queries unresponsive.

The option exists in CoolStorage to run ad hoc SQL queries instead, am I better off doing this instead for more complex queries? Or am I worrying over nothing?

CSList<Team> teams = Team.List();

// Counting number of objects
var d = from t in teams
        select new
        {
            TeamID = t.TeamID,
            TeamName = t.TeamName,
            NoUsers = t.SysuserTeams.Count
        };

// Using property added to Team class
var e = from t in teams
        select new
        {
            TeamID = t.TeamID,
            TeamName = t.TeamName,
            NoUsers = t.NumberOfUsers
        };

DataGridView dgv = this.dgvTeams;
dgv.DataSource = d.ToList();
// Same result as 
dgv.DataSource = e.ToList();
  • 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-16T05:28:38+00:00Added an answer on June 16, 2026 at 5:28 am

    Having seen from the SQL log being generated that it was running a new query for each row in the Teams result, I got in touch with the CoolStorage developers who kindly responded a neat solution.

    There are two options, either the OneToMany property for Sysusers can be tagged as [Prefetch] or this can be explicitly specified for each query such as Team.List().WithPrefecth("Users"). Either way, it now only runs one additional query for the user records, rather than a query per row

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

Sidebar

Related Questions

I have a DataGridView being populated using CoolStorage (ORM) CSList class as its DataSource.
Using the following as an example (with $db being a previously created database connection
I'm using CoolStorage in a project where I have some Many-to-Many relationships. Some of
I'm writing an app for wp7 using coolstorage and sqlite as the database. The
I am retrieving data from an Access database using CoolStorage , and can successfully
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Android NDK is it possible (from native C-code) to get a list of
Using MATLAB, you have to start with a uniform distribution between (0,1). You need
For an application used for managing booktitles and such, I'm using CoolStorage as an

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.