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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:19:58+00:00 2026-06-01T10:19:58+00:00

I am using ObjectContext.ExecuteStoreQuery to return a list of entities, about 30K. I need

  • 0

I am using ObjectContext.ExecuteStoreQuery to return a list of entities, about 30K.

I need to improve performance so I will be “selecting” 4 properties that I really need, instead of the total 20 properties.

I could create a DTO with these 4 properties and pass it to ObjectContext.ExecuteStoreQuery, but I would prefer to use a DataReader, iterate over the 30K, and build my list.

I tried both options and it “seems” they take the same time (did not measure it). My question is -does ObjectContext.ExecuteStoreQuery iterate over the result set, as I am doing manually with a DataReader?

I found this in MSDN, but does not really answer my question. Thank you.

Calling the ExecuteStoreQuery method is equivalent to calling the
ExecuteReader method of the DbCommand class, only ExecuteStoreQuery
returns entities and the ExecuteReader returns property values in the
DbDataReader.

  • 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-01T10:20:00+00:00Added an answer on June 1, 2026 at 10:20 am

    ExecuteStoreQuery returns a System.Data.Objects.ObjectResult and it query directly the database using TSQL, you won’t have a stream but just a collection of all the objects queried.

    http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx

    If I understand correctly this is not what you want.

    If you want to query data in some sort of way similar to a classic ADO.NET DataReader you should query directly the EntityClient, it is different from using Linq To Entities or ESQL because you do not pass through the ObjectContext, and the query will not materializes any object!

    using (EntityConnection conn = new EntityConnection("name=SampleEntities"))
    {
        conn.Open();
        EntityCommand cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT VALUE c FROM SampleEntities.Contacts AS c WHERE c.FirstName='Robert'";
        using (EntityDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection))
        {
            while (rdr.Read())
            {
                var firstname = rdr.GetString(1);
                var lastname = rdr.GetString(2);
            }
        }
        conn.Close();
    }
    

    It is helpful if you need just to query some read-only data you need to display in some way, it is no different from creating any other provider command and setting its CommandText, but The CommandText here is the Entity SQL expression and you obviously query the EDM that i think it is why you are using EF.

    Hope this helps

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

Sidebar

Related Questions

I'm using self-tracking entities with EF 4.0 and I see that there's no IsLoaded
I am using EntityFramework to persist my entities. The problem I have is that
I'm using .NET 3.5 SP1 in ASP.NET MVC application. While using ObjectContext with Http
I'm using ADO.NET EF in an MVC application. I'm considering putting the ObjectContext inside
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I'm trying to develop a extension ( IExtension<OperationContext> ) for System.ServiceModel.ObjectContext using TDD. The
I'm using Entity framework in web application. ObjectContext is created per request (using HttpContext),
I'm having trouble adding an Entity Framework entity to a ObjectContext's EntitySet automatically using

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.