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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:38:59+00:00 2026-06-14T10:38:59+00:00

I’m looking exactly the same How to efficiently query with filter on children at

  • 0

I’m looking exactly the same

How to efficiently query with filter on children at different levels?

but “in lambdas” syntax.

I am really need this, can anybody help? Thanks!

  • 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-14T10:39:00+00:00Added an answer on June 14, 2026 at 10:39 am

    Here is the code snippet from the post you referenced in both the query syntax and the lambda syntax: https://stackoverflow.com/a/12324116/670028:

    LINQ query syntax:

    var listOfString = new List<string>() { "String1", "String2" };
    
    var customers =
    (
        from a in session.Query<A>()
        from b in a.B
        from c in b.C
        where a.Status == "Active"
                && listOfStrings.Contains( b.SomeField )
                && listOfStrings.Contains( c.someOtherField )
        select a )
        .ToList();
    

    LINQ lambda syntax:

    var listOfString = new List<string>() { "String1", "String2" };
    
    var customers =
        (
            session.Query<A>()
                .SelectMany( a => a.B, ( a, b ) => new { a, b } )
                .SelectMany( @t => b.C, ( @t, c ) => new { @t, c } )
                .Where( @t => a.Status == "Active"
                                && listOfStrings.Contains( b.SomeField )
                                && listOfStrings.Contains( c.someOtherField ) ).
                Select
                ( @t => a ) )
            .ToList();
    

    As you can see, it’s not as “clean” as the LINQ query syntax because you have to continue to project into a new anonymous type each time you use the .SelectMany() method. It can also get a little confusing with the all of those variable names which is why I tend to use the LINQ query syntax instead of lambdas when I need to perform queries like this.

    And just for fun, here is an example of using .SelectMany() that looks a little better and more realistic by giving the anonymous types more meaningful names:

    public void Get_StarPowerCorporations_PendingShipment_Orders_Shipping_To_NewYork_Or_Chicago()
    {
        var session = UnitOfWork.Current.GetSession();
    
        var listOfCities = new List<string> { "New York", "Chicago" };
    
        var customerAndOrders = session.Query<Customer>()
            .SelectMany( c => c.Orders, ( Customer, Orders ) => new { Customer, Orders } )
            .SelectMany( CustomerAndOrders => CustomerAndOrders.Orders.OrderDetails, ( CustomerAndOrders, OrderDetails ) => new { CustomerAndOrders, OrderDetails } )
            .Where( x => x.CustomerAndOrders.Customer.CompanyName == "StarPower Corporatation"
                            && x.CustomerAndOrders.Orders.Status == "Pending Shipment"
                            && listOfCities.Contains( x.OrderDetails.City ) )
            .Select( x => x.CustomerAndOrders.Customer )
            .Fetch( x => x.Orders )
            .ToList();
    }
    
    public class Customer
    {
        public int CustomerId { get; set; }
        public string CompanyName { get; set; }
        public IList<Address> Addresses { get; set; }
        public IList<Order> Orders { get; set; }
    }
    
    public class Address
    {
        public int AddressId { get; set; }
    }
    
    public class Order
    {
        public int OrderId { get; set; }
        public string Status { get; set; }
        public IList<OrderDetail> OrderDetails { get; set; }
    }
    
    public class OrderDetail
    {
        public int OrderDetailId { get; set; }
        public string City { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.