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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:43:27+00:00 2026-06-08T21:43:27+00:00

I have a generic type class Filter that has takes some lambda expressions to

  • 0

I have a generic type class Filter that has takes some lambda expressions to select values from the type so that the class is reusable. That class is used in another generic type class Search which will use Filter to select distinct items of the type which will eventually be used in a drop down list.

I removed the unimportant code for these.

public class Filter<T>
{
   public string Name;
   public Func<T, string> Key;
   public Func<T, string> Value;
}

public class Search<T>
{
   MyDBContext db = new MyDBContext();
   IQueryable<T> Model = db.Stuff.OrderBy(a => a.TermID);
   Filter filter = new Filter(
      Name: "Term",
      Value: a => a.TermID.ToString(),
      Key: a => a.Term.TermType.Name
   );

   var filterItems = Model
      .Select(a => new { Key = filter.Key(a), Value = filter.Value(a)})
      .OrderBy(t => t.Key)
      .Distinct()
      .ToArray();
}

I get the run time error: The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.
I have tried using strong types instead of anonymous types, and using Expression<Func<T,string>> in Filter.

After hours of searching and trying different things, I’m not sure how to make this work.
Thank you for your help.

  • 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-08T21:43:29+00:00Added an answer on June 8, 2026 at 9:43 pm

    Your problem can be expressed much more simply, eg this reproduces it:

    Func<SomeClass, int> x = t => t.ID;
    var y = db.SomeClasses.Select(c => x(c)).ToArray();
    

    It compiles fine but gives the same error at runtime because you are invoking a compiled function. That part “t => t.ID” is complied code (at least to IL) and linq cannot read this to convert it to SQL. It can only convert an expression tree to SQL. The solution to the above case is fairly simple, I’m not sure how this will translate to your situation but it should be possible.

    Expression<Func<SomeClass, int>> x = t => t.ID;
    var y = db.SomeClasses.Select(x).ToArray();
    

    There is also the option of moving the function call into linq to objects so that it doesn’t need to be translated to sql (everything after “AsEnumerable” is processed on the client). This allows much greater flexibility in what can be placed in the function and will eliminate the type of errors you are getting. This will also eliminate the need for call to SqlFunctions (see below). The downside is that more rows might be returned than needed from the server.

    Func<SomeClass, int> x = t => t.ID;
    var y = db.SomeClasses.AsEnumerable().Select(c => x(c)).ToArray();
    

    Your last problem is that EF doesn’t like the ToString method and you will need to use SqlFunctions.StringConvert which is fairly crappy. See here: int to string in Entity Framework

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

Sidebar

Related Questions

I have a generic class that takes a type T . Within this class
I have a base class that has methods that use a generic type in
I have a Java class that takes a generic type parameter and a class
I have generic type that looks like: public class GenericClass<T, U> where T :
I have a Base class that needs a Generic type. That can be either
I have a parameterized generic class X which takes a type T. On which
I have a class which has some properties of type List<float> , List<int> etc.
Is there some way to have a generic type with a parameterless constructor that
I have a generic type that is parameterized on some Enum, declared like this:
This is best explained using code. I have a generic class that has a

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.