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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:52:32+00:00 2026-05-12T16:52:32+00:00

I am trying to chain multiple compiled linq queries together. I have succeeded in

  • 0

I am trying to chain multiple compiled linq queries together. I have succeeded in chaining two queries together, but I cannot get a chain of three to work correctly. So here is a reduction of my code to recreate the issue. My two questions are: ‘Why isn’t this working?’ and ‘Is there a better way to keep the performance benefit of compiled queries and also avoid duplication of base query logic that is commonly used?’

Define the following two queries:

Func<DataContext, IQueryable<User>> selectUsers = 
    CompiledQuery.Compile(
        (DataContext dc)=>dc.Users.Select(x=>x)
    );
//        
Func<DataContext, string, IQueryable<User>> filterUserName = 
    CompiledQuery.Compile(
        (DataContext dc, string name) =>
            selectUsers(dc).Where(user=>user.Name == name)
    );

Calling and enumerating the chain works fine:

filterUserName(new DataContext(), "Otter").ToList();

Add a third query to the chain:

Func<DataContext, string, int, IQueryable<User>> filterUserAndGroup =     
    CompiledQuery.Compile(
        (DataContext dc, string name, int groupId) => 
            filterUserName(dc, name).Where(user=>user.GroupId == groupId)
    );

Calling the chain does not work:

filterUserAndGroup(new DataContext(), "Otter", 101);

System.InvalidOperationException:
Member access ‘String Name’ of ‘User’
not legal on type
‘System.Linq.IQueryable1[User].. at
System.Data.Linq.SqlClient.SqlMember.set_Expression(SqlExpression
value) at
System.Data.Linq.SqlClient.SqlFactory.Member(SqlExpression
expr, MemberInfo member) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.AccessMember(SqlMember
m, SqlExpression expo) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitMember(SqlMember
m) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitExpression(SqlExpression
expr) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitBinaryOperator(SqlBinary
bo) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitExpression(SqlExpression
expr) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect
select) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitAlias(SqlAlias
a) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource
source) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect
select) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitIncludeScope(SqlIncludeScope
scope) at
System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode
node) at
System.Data.Linq.SqlClient.SqlBinder.Bind(SqlNode
node) at
System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape
resultShape, Type resultType, SqlNode
node, ReadOnlyCollection
1
parentParameters, SqlNodeAnnotations
annotations) at
System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression
query, SqlNodeAnnotations annotations)
at
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Compile(Expression
query) at
System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext
context, Object[] args) at
System.Data.Linq.CompiledQuery.Invoke(TArg0
arg0, TArg1 arg1) at TestMethod() in
….

  • 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-12T16:52:32+00:00Added an answer on May 12, 2026 at 4:52 pm

    Looks like you need to convert your first compiled query to a list before executing the second one. In theory that should have caused an error with your two queried chain as well.

    From MSDN CompiledQuery:

    If a new query operator is applied to the result of the delegate execution, an exception is generated.

    When you want to execute a query operator over the result of executing a compiled query, you must translate the result to a list before operating on it.

    Perhaps this code will fix it although that could have implications for the roundtrips back to the database if you’re using LINQ to SQL.

    filterUserName(dc, name).ToList().Where(user=>user.GroupId == groupId)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to setup my swap chain Buffer but I get the following
I have a number of dropdown lists that I'm trying to chain together and
We're having an issue trying to chain selectors together. We are trying to get
I have been trying to find a way to chain these methods together in
I have a function with a chain of filters in jQuery. I am trying
I'm trying to chain two named_scopes in my User model. The first: named_scope :commentors,
I'm trying to create a chain of function calls using two objects. I've added
I have two LINQ expressions that I think I should be able to combine
I'm trying to chain dropdown list events. I have these data: Name auidi (a4{
I've been trying to chain Arel queries using scopes, instead of just using some

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.