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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:38:00+00:00 2026-06-11T07:38:00+00:00

So I recently discovered that you can force Entity Framework not to translate your

  • 0

So I recently discovered that you can force Entity Framework not to translate your projection into SQL by specifying a Func<T, TResult> to the .Select() extension method rather than an expression. This is useful when you want to transform your queried data, but that transformation should happen in your code rather than on the database.

For example, when using EF5’s new Enum support and trying to project that to a string property in a DTO, whereas this would fail:

results.Select(r => new Dto { Status = r.Status.ToString() })

this would work:

results.Select(new Func<Record, Dto>(r => new Dto { Status = r.Status.ToString() }));

because in the first (expression) case, EF can’t figure out how to translate Status.ToString() to something the SQL database could perform, but as per this article Func predicates aren’t translated.

Once I had this working, it wasn’t much of a leap to create the following extension method:

public static IQueryable<T> Materialize<T>(this IQueryable<T> q)
{
    return q.Select(new Func<T, T>(t => t)).AsQueryable();
}

So my question is – are there any pitfalls I should be wary of when using this? Is there a performance impact – either in injecting this do-nothing projection into the query pipeline or by causing EF to not send the .Where() clause to the server and thereby send all the results over the wire?

The intention is to still use a .Where() method to filter the results on the server, but then to use .Materialize() before .Select() so that the provider doesn’t try to translate the projection to SQL Server:

return Context.Record
    .Where(r => // Some filter to limit results)
    .Materialize()
    .Select(r => // Some projection to DTO, etc.);
  • 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-11T07:38:01+00:00Added an answer on June 11, 2026 at 7:38 am

    Simply using AsEnumerable should do the same:

    return Context.Record
                  .Where(r => // Some filter to limit results)
                  .AsEnumerable() // All extension methods now accept Func instead of Expression
                  .Select(r => // Some projection to DTO, etc.);
    

    There is also no reason in your Materialize method to go back to IQueryable because it is not a real IQueryable translated to another query any more. It is just IEnumerable.

    In terms of performance you should be OK. Everything before materialization is evaluated in the database and everything after materialization in your code. Moreover in both your and my example query has still deferred execution – it is not executed until something enumerates the query.

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

Sidebar

Related Questions

I recently discovered SignalR, seems that it can fit into high-load projects with hundreds
I recently discovered that I can use lambdas to create simple event handlers. I
I recently discovered that in C++ you can overload the function call operator, in
I recently discovered that a sql query that was running fine earlier is now
I recently discovered at work that it is the policy not to use compiler
I recently discovered that you can conditionally assign a value with an if-else block.
I recently discovered that a method in a derived class can only access the
I recently discovered that you can set breakpoints in Xcode that will print to
I recently discovered that you can describe an Android custom drawable in an XML
I recently discovered that the java.lang.String.substring method does not return a new string, but

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.