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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:35:22+00:00 2026-06-06T11:35:22+00:00

EDIT: More detailed question. I am working on batched operations in nHibernate, specifically for

  • 0

EDIT: More detailed question.

I am working on batched operations in nHibernate, specifically for In queries to overcome the 2100 parameter limit size in SQL Server.

For this, I have created a class with this constructor (this is a very simplified version):

BatchedQuery(session.Query<Foo>(), allValues, (l, e) => l.Contains(e.Id));

...

public BatchedQuery(IQueryable<TEntity> query, IList<TValue> allValues, Expression<Func<IList<TValue>, TEntity, bool>> predicate)
{
   List<TValue> values = ...; // Select a batch from allValues
   ...

   // I want to pass the values to the expression passed in...
   // something like this, without using Compile: 
   // e => predicate.Compile()(values, e)

   // using JKor's method, I tried this...
   ParameterExpression param = Expression.Parameter(typeof(TEntity), "e");
   Expression<Func<TEntity, bool>> expr2 =
       Expression.Lambda<Func<TEntity, bool>>(Expression.Invoke(predicate,
           Expression.Constant(batchOfValues), param), param);

   query = query.Where(expr2);

   // Do something with the query...
}

// Somewhere else..
// This causes the exception
batchedQuery.ToList();

The above is causing nHibernate to throw a KeyNotFoundException.

Here is the stack trace:

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at NHibernate.Param.NamedParameterSpecification.SetEffectiveType(QueryParameters queryParameters)
at NHibernate.Param.ParametersBackTrackExtensions.ResetEffectiveExpectedType(IEnumerable`1 parameterSpecs, QueryParameters queryParameters)
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.ResetEffectiveExpectedType(IEnumerable`1 parameterSpecs, QueryParameters queryParameters)
at NHibernate.Loader.Loader.CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.MultiQueryImpl.AggregateQueriesInformation()
at NHibernate.Impl.MultiQueryImpl.get_Parameters()
at NHibernate.Impl.MultiQueryImpl.CreateCombinedQueryParameters()
at NHibernate.Impl.MultiQueryImpl.List()
at NHibernate.Impl.FutureQueryBatch.GetResultsFrom(IMultiQuery multiApproach)
at NHibernate.Impl.FutureBatch`2.GetResults()
at NHibernate.Impl.FutureBatch`2.get_Results()
at NHibernate.Impl.FutureBatch`2.GetCurrentResult[TResult](Int32 currentIndex)
at NHibernate.Impl.FutureBatch`2.<>c__DisplayClass4`1.<GetEnumerator>b__3()
at NHibernate.Impl.DelayedEnumerator`1.<get_Enumerable>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at NovusERP.Data.Helpers.BatchedQuery`2.ToList() in D:\Short Utilities\Novus\NovusERP\NovusERP.Data\Helpers\BatchedQuery.cs:line 63
at NovusERP.Modules.Payroll.Attendance.AttendanceViewModel.GetEmployees(IList`1 selectedEmployeeIds) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceViewModel.cs:line 79
at NovusERP.Modules.Payroll.Attendance.AttendanceViewModel..ctor(MonthYear currentMonth, IList`1 selectedEmployeeIds) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceViewModel.cs:line 47
at NovusERP.Modules.Payroll.Attendance.AttendanceView..ctor(MonthYear currentMonth, IList`1 selectedEmployees) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceView.xaml.cs:line 18
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()

Can anybody point me to the right direction? Any help will be highly appreciated.

Regards,
Yogesh.

  • 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-06T11:35:25+00:00Added an answer on June 6, 2026 at 11:35 am

    I am posting my answer so that others can benefit from it.

    The best way to do what I wanted was to use ExpressionVisitor and Expression.Lambda and make a copy of the whole expression with the appropriate changes. This class is an internal class in 3/3.5, so if you want to use this class for 3/3.5, here is the complete implementation of the class. There are tons of tutorials available for the same on the net.

    Secondly, anyone who wants to get a tool for parsing and visualizing expression trees should get the ExpressionTreeVisualizer sample in VS 2008. You will have to convert and compile the sample to VS 2010 for .Net 4.0. This blog post by Patrick Smacchia helps you how.

    One side note to all of the above, nhibernate still throws the exception even after converting the query the way I have explained in this answer. This only happens if I try to convert the query to a future query and then evaluate it. Without converting the query to future, it works fine. I am searching for a solution for the same. I will update the answer accordingly if I find out why it is happening and what is the solution.

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

Sidebar

Related Questions

EDIT italics = more detailed explanation added to the question. Thanks. I'm building a
-- edit -- I've made the question far more detailed here: Drupal aggregators and
edit: A more pointed question: What is the derivative of softmax to be used
Okay I edit my question, try to explain it more clearly: I have a
Edit : I tried to format the question and accepted answer in more presentable
EDIT: A bit more detailed HTML document... In short- how do I actually do
Edit 2: Actually SomeEventHandler is more concise than OnSomeEventHandler : If I let Visual
[EDIT] I am changing this to more concisely explain what my problem was, after
More often than I like when designers edit some of our sites' pages, they
Edit: I've got the solution and have described it a bit more at 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.