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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:54:31+00:00 2026-06-18T00:54:31+00:00

The following Entity Framework query runs without error. Predicate<Program> filterProgram; if (programId.HasValue) filterProgram =

  • 0

The following Entity Framework query runs without error.

Predicate<Program> filterProgram;
if (programId.HasValue)
    filterProgram = (p => p.Id == programId && !p.IsDeleted);
else
    filterProgram = (p => !p.IsDeleted);

var analytics = (from a in repository.Query<Analytic>()
                 where (a.Marker == "Open" || a.Marker == "LastTouch") &&
                 a.EntityType == "Proposal" &&
                 a.Site == "C"
                 join p in repository.Query<Program>()
                 on a.EntityId equals p.Id
                 //where filterProgram(p)
                 group a
                 by new { a.LoginSessionId, a.EntityId, p.Id, p.Name } into g
                 let f = g.OrderBy(x => x.TimestampUtc).FirstOrDefault(x => x.Marker == "Open")
                 where f != null
                 let t = g.FirstOrDefault(x => x.Marker == "LastTouch" && x.TimestampUtc > f.TimestampUtc)
                 select new
                 {
                     ProgramId = g.Key.Id,
                     Program = g.Key.Name,
                     ProposalId = g.Key.EntityId,
                     FirstOpen = f,
                     LastTouch = (t ?? f).TimestampUtc
                 }).ToList();

However, if I uncomment the line where filterProgram(p), I get the run-time error:

The LINQ expression node type ‘Invoke’ is not supported in LINQ to Entities.

I was expecting that LINQ would be able to incorporate my predicate into the query and convert it to SQL. Why am I getting this error, and is there a way to dynamically modify a where predicate this way?

  • 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-18T00:54:33+00:00Added an answer on June 18, 2026 at 12:54 am

    Change filterProgram‘s type to Expression<Func<Program, bool>> and then it should be usable in a LINQ Where clause.

    One caveat, however: I managed to get it to work in method chain syntax, but not in query syntax.

    For example, this works:

    dataContext.Programs.Where (filterProgram)
    

    but this does not:

    from p in dataContext.Programs
    where filterprogram 
    

    (The compiler complains that it cannot resolve method Where, which is available on both IEnumerable and IQueryable.)

    In your case, it might be acceptable to replace the line

    join p in repository.Query<Program>()
    

    with

    join p in repository.Query<Program>().Where(filterProgram)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering how the following sql query would look in linq for Entity Framework...
The .NET Entity framework is giving me the following error: The table/view 'Foo.dbo.vwFoo' does
Any ideas why does the entity framework in LINQ gives following strange error: Unable
Hey getting the following error when running my MVP Entity Framework App : Keyword
I'm trying to use Entity Framework to query database and I have following code
How to implement following query of SQL in entity framework. SELECT * FROM Users
I have the following Entity Framework query: var results = from r in db.Results
I have entity framework code as shown below.I am getting following error in where
I am using entity framework with the following linq query IQueryable<Order_Details> query = (from
I have the following query, which is using Entity Framework. Analytic firstSent = (from

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.