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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:56:02+00:00 2026-06-08T15:56:02+00:00

Trying to write dynamic queries using the LINQ provider for NHibernate, but I am

  • 0

Trying to write dynamic queries using the LINQ provider for NHibernate, but I am having issues. My understanding was that LINQ queries were deferred until called, (i.e. with ToList()), so I have the following code:

string[] filteredIds = new[] { "someIdNotInUse"};

var result = _products
    .GetAll()
    .Skip(0)
    .Take(10);

if (filteredIds != null) 
{
    result.Where(x => x.Child1.Child2.Any(z => filteredIds.Contains(z.Child3.Id)));
}

var r = result.ToList();

The Where filter in the conditional block is not applied; when I run .ToList, I get records where I expect none. However, if I remove the where filter and append it directly to the _products call, it works as expected. Am I misunderstanding how the LINQ provider works? How is creating a query like this possible, without rewriting the query for every possible filter condition and combination?

  • 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-08T15:56:04+00:00Added an answer on June 8, 2026 at 3:56 pm

    Methods in LINQ don’t affect the object they’re called on – they return a new object representing the result of the call. So you want:

    if (filteredIds != null) 
    {
        result = result.Where(...);
    }
    

    (Think of it as being a bit like calling Replace or Trim on a string – the string is immutable, so it’s only the return value which matters.)

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

Sidebar

Related Questions

I'm trying to write a dynamic Linq 2 Sql query using Expressions trees but
I am trying to write a dynamic lambda or query but it occurs an
I am trying write a function that generates simulated data but if the simulated
I am trying to write a Dynamic Query which uses a CTE. But I
I'm trying to write dynamic method that calls Parallel.ForEach. I have checked a IL
I am trying to learn how to write more dynamic web sites that use
Im trying to write a function that creates set of dynamic sublists each containing
I'm trying to write a custom filter for Dynamic data that will allow me
I'm trying to write a dynamic control in Microsoft MVC that lets me edit
I'm trying to write a dynamic form for models that allow users with different

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.