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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:44:35+00:00 2026-06-09T16:44:35+00:00

I have problem with the NHibernate’s second level cache. When I use query: var

  • 0

I have problem with the NHibernate’s second level cache. When I use query:

        var items1 = Session.Query<Row>()
            .Cacheable();
            .Fetch(x => x.Field)
            .OrderBy(x => x.Field.Value)
            .ToList();

Everything is fine – the query is cached. But when I want to use Dynamic Linq (a link):

       var items2 = Session.Query<Row>()
            .Cacheable();
            .Fetch(x => x.Field)
            .OrderBy("Field.Value")
            .ToList();

The query is not cached. Interesting thing is that, when I delete code line:

            .Fetch(x => x.Field)

caching works again. So the problem is with using Fetch and dynamic linq OrderBy methods together.

EDIT:

When I try do debug NH code (QueryKey class), debugger tells me that these two queries do not have the same ResultTransformer (and deeper: a listTransformation private instance).

Any ideas?

Chris

  • 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-09T16:44:36+00:00Added an answer on June 9, 2026 at 4:44 pm

    Ok, I know what is the reason.

    Dynamic Linq doesn’t use Parameter Names in Linq Expressions. E.g. if I want to sort using lambda statemant, I write:

    query.OrderBy(item => item.Name)
    

    Above we see an item lambda parameter name.

    When I use Dynamic linq:

    query.OrderBy("Name")
    

    in the result Queryable the lambda parameter in OrderBy mehod has no name (like item written above). We can illustrate the result like this:

    query.OrderBy( => .Name)
    

    And now, when NHibernate is decoding that Queryable expression and finds there an expression parameter that has no name, NH gives it a random name using GUID class. So every ordering using dynamic linq produces a Queryable Expression that has inconstant lambda parameter. This is the reason why NHibernate thinks that: query.OrderBy("Name") and query.OrderBy("Name") are not the same – they have another lamda parameters generated every time from scratch.

    SOLUTION

    If you want to fix it, you have to modify Dynamic Linq library.

    1. In method ExpressionParser.ProcessParameters change line:

      if (parameters.Length == 1 && String.IsNullOrEmpty(parameters[0].Name))
      

      to:

      if (parameters.Length == 1 && (parameters[0].Name == "it" || String.IsNullOrEmpty(parameters[0].Name)))
      
    2. In method DynamicQueryable.OrderBy change line:

      Expression.Parameter(source.ElementType, "")
      

      to:

      Expression.Parameter(source.ElementType, "it")
      

    Now, query.OrderBy("Name") will produce query.OrderBy(it => it.Name).

    Cheers!

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

Sidebar

Related Questions

I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have a problem with nhibernate mapping. I use the nhibernate 3.2 mapping by
I query my NHibernate datasources using a Linq Expression. The problem I have with
I have a problem trying the following with nHibernate: Eager loading. Use selects (here
I have the following problem with an NHibernate query. one table LearnerDocuments : LearnerNumber
I have this problem. I have a module (module 1) that use Nhibernate to
I have a problem with: NHibernate.Cfg.Configuration.SetProperties() Not accepting the IDictionary: NHibernateConfigHandler I get the
I have a problem using Linq to NHibernate to load an object and eagerly
I have a class that is mapped to a table using NHibernate. The problem
Using MVC3 with NHibernate, I am having a problem with dropdowns. I have 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.