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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:58:10+00:00 2026-05-27T20:58:10+00:00

This is a follow up to a question I asked earlier seen here: Confused

  • 0

This is a follow up to a question I asked earlier seen here:

Confused about passing Expression vs. Func arguments

The accepted answerer there suggests refactoring an Expression referencing local objects into something that Linq to Entities can actually execute against the backing store (in my case SQL Server)

I’ve spent a long time trying to come up with something that will work for what I’m doing. My original

Func<Thing, bool> whereClause

was referencing a local Dictionary object which Linq to Entities or SQL could not understand at runtime. I tried refactoring into multiple lists which faked a dictionary, and Arrays after that. Each time, I got runtime errors complaining about the context doesn’t recognize things like the methods on a List, or array indexers.

Eventually I gave up and just provided an additional method which takes a Func argument for when I cannot come up with the proper Expression.

I’m not trying to find a solution to my specific problem, I’m just wondering in general if it is always possible to convert, say a

Func<Thing, bool>

to an equivalent

Expression<Func<Thing, bool>>

which can run against Linq to Entities.
Or if there are many examples of querys where you simply must pull the data into memory first.

  • 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-27T20:58:10+00:00Added an answer on May 27, 2026 at 8:58 pm

    You don’t convert a Func to an expression tree – the compiler converts a lambda expression to an expression tree… and no, that’s not always possible. For example, you can’t convert a statement lambda to an expression tree:

    Expression<Func<string, int>> valid = text => text.Length;
    
    Expression<Func<string, int>> invalid = text => { return text.Length; };
    

    There are various other restrictions, too.

    Even when you can create an expression tree (and if you do it manually you can build ones which the C# compiler wouldn’t, particularly in .NET 4) that’s not the same thing as the expression tree representing something that LINQ to SQL (etc) can translate appropriately.

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

Sidebar

Related Questions

This is a follow-up question to this question I asked earlier. Btw thanks Neil
This is a follow up question to a previous question I asked about calculating
This is a follow-on question from the one I asked here . Can constraints
This is a follow-up to another question I asked earlier today. I am creating
This is a follow-up to a question I'd asked earlier which phrased this as
This is a follow up to the question asked here: Groovy parsing text file
This is kind of a follow-up question to a question I asked over here
This is a follow up to a question I asked earlier today regarding the
this is actually a follow up to a question I asked yesterday about problems
This is a follow-up to a question I asked last year about setting up

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.