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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:57:26+00:00 2026-05-27T22:57:26+00:00

I have Linq query and would like to execute it immediately and then manipulate

  • 0

I have Linq query and would like to execute it immediately and then manipulate data. Now in the code below the first (1) Linq query is executed when second (2) Linq query is executed. I would like to execute first(1) query first, how to do that?

// 1
var statistic = DataAccess.Instance.Statistics
                    .Where(p => p.DateStamp >= fromDate && p.DateStamp <= DateTime.UtcNow && p.UserId == userId)
                    .Select(p => new {p.DateStamp.Year, p.DateStamp.Month, p.DateStamp.Day });


values = new int[interval];
labels = new string[interval];

for (var i = 0; i < labels.Length; i++)
{
    // 2
    var recordsCount = statistic.Count(p => p.Year == dayStep.Year && p.Month == dayStep.Month && p.Day == dayStep.Day);
}
  • 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-27T22:57:27+00:00Added an answer on May 27, 2026 at 10:57 pm

    I think you are missing an important concept in Data Manipulation in .NET

    Deferred and Immediate Fetching

    An important point to emphasize is that by default, LINQ to SQL retrieves the data from the
    database only when you request it and not when you define a LINQ to SQL query or create a
    Table collection. This is known as deferred fetching.

    When the foreach loop starts, LINQ to SQL creates and runs a SQL SELECT statement derived
    from the LINQ to SQL query to create an ADO.NET DataReader object. Each iteration of the
    foreach loop performs the necessary GetXXX methods to fetch the data for that row. After
    the final row has been fetched and processed by the foreach loop, LINQ to SQL closes the
    database connection.

    Deferred fetching ensures that only the data an application actually uses is retrieved from
    the database. However, if you are accessing a database running on a remote instance of SQL
    Server, fetching data row by row does not make the best use of network bandwidth. In this
    scenario, you can fetch and cache all the data in a single network request by forcing immediate
    evaluation of the LINQ to SQL query. You can do this by calling the ToList or ToArray
    extension methods, which fetch the data into a list or array when you define the LINQ to SQL
    query, like this:

    var productsQuery = from p in products.ToList()
    select p;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to execute a LINQ query with a dynamic where clause depending
Linq and EF4. I have this Linq query in query syntax I would like
I have a Linq query that looks something like this: var myPosse = from
I have a Linq query that looks something like this: var query = from
I have a LINQ query that returns some object like this... var query =
I would like to execute a Linq to Sql statement that captures the count
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
I have a linq query Context.Set<Entity>().where(x=>x.condition == true).select(x=> new ViewModel{Property = x.Property}); I would
I have the following rss feed which I would like to query to get
I have a linq query that i'd like to get the query syntax for.

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.