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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:23:11+00:00 2026-05-25T23:23:11+00:00

I have a page that pulls together aggregate data from two different tables. I

  • 0

I have a page that pulls together aggregate data from two different tables. I would like to perform these queries in parallel to reduce the latency without having to introduce a stored procedure that would do both.

For example, I currently have this:

ViewBag.TotalUsers = DB.Users.Count();
ViewBag.TotalPosts = DB.Posts.Count();
// Page displays both values but has two trips to the DB server

I’d like something akin to:

var info = DB.Select(db => new { 
   TotalUsers = db.Users.Count(), 
   TotalPosts = db.Posts.Count());
// Page displays both values using one trip to DB server.

that would generate a query like this

SELECT (SELECT COUNT(*) FROM Users) AS TotalUsers, 
       (SELECT COUNT(*) FROM Posts) AS TotalPosts

Thus, I’m looking for a single query to hit the DB server. I’m not asking how to parallelize two separate queries using Tasks or Threads

Obviously I could create a stored procedure that got back both values in a single trip, but I’d like to avoid that if possible as it’s easier to add additional stats purely in code rather than having to keep refreshing the DB import.

Am I missing something? Is there a nice pattern in EF to say that you’d like several disparate values that can all be fetched in parallel?

  • 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-25T23:23:11+00:00Added an answer on May 25, 2026 at 11:23 pm

    It seems like there’s no good way to do this (yet) in EF4. You can either:

    1. Use the technique described by adrift which will generate a slightly awkward query.
    2. Use the ExecuteStoreQuery where T is some dummy class that you create with property getters/setters matching the name of the columns from the query. The disadvantage of this approach is that you can’t directly use your entity model and have to resort to SQL. In addition, you have to create these dummy entities.
    3. Use the a MultiQuery class that combines several queries into one. This is similar to NHibernate’s futures hinted at by StanK in the comments. This is a little hack-ish and it doesn’t seem to support scalar valued queries (yet).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have currently created a facebook like page that pulls notifications from different tables,
I have a page that pulls 2-3 chunks of data from sql. these chunks
I have a php page that pulls data from a mysql database based on
I have a log in page that pulls information from a data base, I
I have a ajax javascript method that pulls data from a page etc. I
I would like to have filtering page that performs ajax requests to asynchronously update
I have a page that pulls in data via AJAX. As well as this
I have a page that pulls up information based on an ID from the
I have just been implementing a google map, that pulls data from the yelp
Have a simple page that pulls results from MySQL and displays them in a

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.