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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:03:14+00:00 2026-05-30T07:03:14+00:00

I’m tasked with generating a list of member data using the NHibernate Criteria API.

  • 0

I’m tasked with generating a list of member data using the NHibernate Criteria API. I need to incorporate paging and filtering based on checkboxes in the UI. What makes this a bit more complex is that I’m not just fetching data from one entity, but this entity has a HasMany relationship to other entities.

I currently have an error:

Error executing multi Criteria: 
[SELECT DISTINCT TOP 1000 this_MemberID as y0_ 
 FROM _Members
 Left Outer Join _SubMemberTerms ON _SubMemberTerms.MemberID = this_.MemberID
 Left Outer Join _MemberTerms ON _MemberTerms.MemberID = this_.MemberID
 Left Outer Join _ScriptOption ON _ScriptOption.ID = _MemberTerms.ScriptOpID
 WHERE _MagazineID = 100
 AND 
    (_ScriptOption.MagID IN (1234,5678,9101,.....) 
        OR _ScriptOption.MemberID IS NULL
        OR _ScriptOption.Active = 0)
 AND
    (_SubMemberTerms._ScriptOpID IN (1234,5678,9101,.....)
        OR _SubMemberTerms.ID IS NULL);]

The Inner exception is: The value \”5554302\” is not of type
\”MyBusiness.MemberInfo\” and cannot be used in this generic
collection. Parameter name: value.

Right now I’m just looking at the Member’s ID because I commented every other projection in my projection list out. Otherwise the error would’ve stated “The Value \”System.object[]\”…

My Criteria Code:

var filteredList = CurrentSession.CreateCriteria<MemberInfo>("this_")
                   .SetProjection(Projections.Distinct(Projections.ProjectionList()
                   .Add(Projections.Alias(Projections.Property("ManagedMemberID"), "MemberID"))))
                   .Add(Restrictions.Eq("_MagazineID", (int)magID))
                   .CreateAlias("MemTermsList", "_MemberTerms", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                   .CreateAlias("_MemberTerms.ScriptOpInfo", "_ScriptOption", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                   .CreateAlias("SubTermsList", "_SubMemberTerms", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
                   .SetFirstResult(startposition)
                   .SetMaxResults(1000);

I also have a Criteria made for getting the count of the total query and not just the 1k returned. It’s the same as the Criteria I made for filteredList.

//code for how I'm adding in the MagID's and ScriptOpId's
Disjunction magDisjunction = new Disjunction();
Disjunction subTermsDijunction = new Disjunction();
if(TheCheckBoxThatAppliesIsChecked)
{
    magDisjunction.Add(Restrictions.In("_ScriptOption.MagID", (List<int>)selectedMags))
                  .Add(Restrictions.IsNull("_MemberTerms.MemberID"))
                  .Add(Restrictions.Eq("_MemberTerms.Active", false));

    filteredList.Add(magDisjunction);
}
if(TheOtherCheckBoxThatAppliesIsChecked)
{
    subTermsDisjunction.Add(Restrictions.In("_SubMemberTerms.SciptOpID", (List<int>)selectedScriptOp))
                  .Add(Restrictions.IsNull("_SubMemberTerms.SubMemberTermsID"));

    filteredList.Add(subTermsDisjunction);
}

var finishedList = filteredList.Future<MemberInfo>().ToList<MemberInfo>();
var count = listCount.FutureValue<int>().Value;

EDIT:
I had a typo in my projections.Alias, switched form “MemberID”, to “ManagedMemberID”.

  • 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-30T07:03:16+00:00Added an answer on May 30, 2026 at 7:03 am

    query filteredlist has

    .SetProjection(Projections.Distinct(Projections.ProjectionList().Add(Projections.Alias(Projections.Property("MemberID"), "MemberID"))))
    

    which is the same as

    .SetProjection(Projections.Distinct(Projections.Property("MemberID")))
    

    which means that the query filteredlist returns MemberID but

    var finishedList = filteredList.Future<MemberInfo>().ToList<MemberInfo>();
    

    states that filteredList returns MemberInfo which results in the error

    NOTE:

    the Future() is just a noop since you are calling ToList() immediatly. change it to

    var finishedList = filteredList.Future<int>();
    var count = listCount.FutureValue<int>();
    

    to get query batching

    Update:

    I would get rid of the Projection and use

    int count = CriteriaUtil.Clone(query).SetProjection(Projections.RowCount()).FutureValue<int>();
    var results = query.Future<MemberInfo>();
    
    
    View.MemberCount = count.Value;  // executes both sql together here
    foreach (MemberInfo result in results)
    {
        // do something with the result
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.