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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:52:22+00:00 2026-06-06T05:52:22+00:00

(using Entity Framework) when i write : IEnumerable<string> q = customers /*EF entity*/ .Select

  • 0

(using Entity Framework)

when i write :

IEnumerable<string> q = customers /*EF entity*/
.Select (c => c.Name.ToUpper())
.OrderBy (n => n)

the c# compiler knows how to emit expression trees which in turn , the sql execute :

SELECT UPPER (Name) FROM Customer ORDER BY UPPER (Name)

notice also the order by clause is there

but

i saw this link :

he wrote :

IEnumerable<employee> emp = 
         dc.Employees.Where(x => x.Desc.StartsWith("soft"));
emp = emp.Take(1);

after investigating the final query he saw :

SELECT [t0].[Id], [t0].[Name], [t0].[Address], [t0].[Desc] AS [Desc]
FROM [dbo].[Employee] AS [t0]
WHERE [t0].[Desc] LIKE @p0

notice there is no top clause

why is that ?

shouldn’t Take(x) be added to the query ?

will writing it like this :

IEnumerable<employee> emp = 
         (dc.Employees.Where(x => x.Desc.StartsWith("soft"))).Take(1);

would added the TOP clause to the query being sent to SQL ?

what is going here ?

( I already know that take is not a deferred execution)

  • 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-06T05:52:24+00:00Added an answer on June 6, 2026 at 5:52 am

    Extension methods such as Take() are static methods, and as such they are resolved at compile time.

    The compile time type of emp is IEnumerable<employee> (because it was explicitly declared as one), so the compiler picks Enumerable.Take instead of Queryable.Take, which does not perform any query translation.

    If you would have been lazy and would just have used var instead of a type name:

    var emp = dc.Employees.Where(x => x.Desc.StartsWith("soft"));
    emp = emp.Take(1);
    

    it would have worked, because the compiler would have picked IQueryable<employee> for emp (because the expression you initialize it with is of that type), and thus Queryable.Take for the second call.

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

Sidebar

Related Questions

I write this piece of code with C# using ADO.NET Entity Framework. I found
I am using RIA services with Entity Framework- I have the following sql select
I plan to write my first application using Entity Framework + Repository + Unit
hello, can you help me how to write Linq query (using Entity Framework) for
How would I write a query using entity framework where I need to make
Using Entity Framework 4.3 in one of my data access classes I have generic
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
(USING ENTITY FRAMEWORK 4.3 CODE FIRST) The code is below. I want to actually
When using Entity Framework 4.1, are there alternatives to the naming conventions for Navigation
I am using Entity Framework 4.3.1 and I am trying to insert a new

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.