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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:41:37+00:00 2026-05-26T21:41:37+00:00

So, I have a query like public static IEnumerable<Archive> GetArchivesRecursive(this ISession session, Page rootPage)

  • 0

So, I have a query like

public static IEnumerable<Archive> GetArchivesRecursive(this ISession session, Page rootPage)
{
    var archives = session.Query<Page>().Where(p => p != rootPage && p.Path.StartsWith(rootPage.Path))
    .GroupBy(p => new { Year = p.Published.Year, Month = p.Published.Month })
    .Select(g => new Archive
    {
            ContextPageId = rootPage.Id,
            Year = g.Key.Year,
            Month = g.Key.Month,
            TotalPageCount = g.Count(),
            PublicPageCount = g.Count(p => p.State == PageState.Public && p.Published <= DateTime.UtcNow)
    })
    .ToList();

    // ContextPageId has old value (id of the first rootPage used since app start)
    // Why do I have to do this?
    archives.ForEach(a => a.ContextPageId = rootPage.Id);
    return archives;
}

For some reason ContextPageId property gets value of the first rootPage parameter that was used.

  • 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-26T21:41:38+00:00Added an answer on May 26, 2026 at 9:41 pm

    Well, quite interesting, my NH 3.2 actually fails with MismatchedTreeNodeException for even simplier queries when trying to have value from input in Select inside query. Which version are you using?

    Anyway, looks like you just can’t use values from outside the query in projection (Select) and this is probably NHibernate’s Linq limitation. Your version seems to cache the compiled expression from Select ignoring the fact that it depends from a variable. DateTime value is the same for all calls, too, isn’t it?

    A bit cleaner workaround could go like this:

    .Select(g => new
    {
        Year = g.Key.Year,
        Month = g.Key.Month,
        TotalPageCount = g.Count(),
        PublicPageCount = g.Count(p => p.State == PageState.Public && p.Published <= DateTime.UtcNow)
    })
    .AsEnumerable()
    .Select(g => new Archive
    {
        ContextPageId = rootPage.Id,
        Year = g.Year,
        Month = g.Month,
        TotalPageCount = g.TotalPageCount,
        PublicPageCount = g.PublicPageCount
    })
    .ToList();
    

    EDIT I’ve looked a bit more carefully and this indeed is a NHibernate bug, already known. See this blog post and this JIRA bug entry.

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

Sidebar

Related Questions

I have an extension method defined like so: public static TSource MaxBy<TSource, TResult>(this IEnumerable<TSource>
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a function like this public static string GetNumberOfColumns(string ConnectionString) { StringBuilder sb
I have extension method: public static IQueryable<TResult> WithFieldLike<TResult>( this IQueryable<TResult> query, Func<TResult, string> field,
So I have a function that looks like this: @SuppressWarnings(unchecked) public static <E> Set<E>
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this (Mysql 5.X, PHP - formatted for legibility) $query
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I try to build extension method for IQuerable like this: public static IQueryable<T> FilterByString<T>(this

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.