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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:56+00:00 2026-06-16T05:26:56+00:00

I have a class Mod, which has a member: ICollection<Event> EventList The class Event

  • 0

I have a class Mod, which has a member:

ICollection<Event> EventList

The class Event has a member:

public virtual EventType Type { get; set; }

The class EvenType has member:

   public virtual int Id

I want to get a list of all Events in Mod which have an id of 1 or 2 using NHibernate Criteria. I did this:

var subCriteria = DetachedCriteria.For<Mod>()
    .Add(Restrictions.In("Event.Type", new int[] {1, 2 })
    );
criteria.Add(Subqueries.Exists(subCriteria));

but I get a runtime error saying
Cannot use subqueries on a criteria without a projection.

So, fine, but I don’t know what to put for the Projection. I can find examples of how to do Projections, but nothing that really explains the purpose. I’ve tried various things, but all result in a runtime error:

Message : Value cannot be null.
Parameter name: key
Source : mscorlib
Help link :
ParamName : key

I need to use subquery because I will be adding more when this works.

Can you suggest what to do for Projection?

  • 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-16T05:26:57+00:00Added an answer on June 16, 2026 at 5:26 am

    As documented here: 16.4. Associations it could be done like this:

    IQueryOver<Mod, Event> query = session
      .QueryOver<Mod>()
      .JoinQueryOver<Event>(mod => mod.EventList)
      .WhereRestrictionOn(evnt => evnt.Type.Id).IsIn(new object[] { 1, 2});
    
    var result = query.List<Mod>();
    

    EDIT: pure Criteria API:

    var criteria = session.CreateCriteria<Mod>();
    var sub = criteria.CreateCriteria("EventList", JoinType.LeftOuterJoin);
        sub.Add(new InExpression("Type", new object[] { 1, 2 }));
    
    var result = criteria.List<Mod>();
    

    using detached criteria. In this case, the EventType must have property ModId or refernece to the Mod instance. In the subquery, we have to return list of valid Mod.IDs

    var sub = DetachedCriteria
     .For<Event>()
     .Add(Restrictions.In("Type", new int[] {1, 2 })) // WHERE
     .SetProjection(Projections.Property("ModId")); // Mod.ID the SELECT clause
    
    var criteria = session.CreateCriteria<Mod>();
    criteria.Add(Subqueries.PropertyIn("ID", sub)); // Mod.ID in (select
    var result = criteria.List<Mod>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
We have class lua. In lua class there is a method registerFunc() which is
I have class like this below shown. which contains the shopping items where the
I have class that looks like this: class A { public: class variables_map vm
I am trying to get my old paging class to work which relied on
I have three code. This is the first one in which I get the
I have an index.php file that has 3 includes <?php require_once('mod.php'); $mod = new

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.