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

  • Home
  • SEARCH
  • 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 931551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:31:18+00:00 2026-05-15T20:31:18+00:00

I’m trying to perform an in query on a collection of id objects (implemented

  • 0

I’m trying to perform an “in” query on a collection of id objects (implemented as a simple class with two integer id members) which are mapped as composite-keys and I’m seeing some strange results when I query using the criteria api using Restrictions.In and using NHibernate.Linq using idList.Contains

Here is a sample usage:

    Public Function GetByMultipleIds(ByVal ids As ICollection(Of QualificationKey)) As IList(Of Qualification) Implements IQualificationRepository.GetByMultipleIds
        Dim query = Session.CreateCriteria(Of Qualification)()
        query.Add(Restrictions.In("Id", ids.ToArray()))
        Return query.List(Of Qualification)()
    End Function

Here is the mapping for my key:

    <composite-id name="Id" class="QualificationKey">
        <key-property name="QualificationAreaId" column="QualificationAreaId"/>
        <key-property name="QualificationLevelId" column="QualificationLevelId"/>
    </composite-id>

Here is the resulting SQL that’s generated:

SELECT this_.QualificationAreaId                                                                  as Qualific1_6_2_,
       this_.QualificationLevelId                                                                 as Qualific2_6_2_,
       this_.Version                                                                              as Version6_2_,
       this_.Rank                                                                                 as Rank6_2_,
       (SELECT QualificationArea.QualificationAreaTypeId
        FROM   QualificationArea
        WHERE  QualificationArea.QualificationAreaId = this_.QualificationAreaId) as clazz_2_,
       qualificat2_.QualificationAreaId                                                           as Qualific1_7_0_,
       qualificat2_.Name                                                                          as Name7_0_,
       qualificat2_.QualificationAreaTypeId                                                       as Qualific2_7_0_,
       qualificat2_.QualificationAreaPermissionId                                                 as Qualific4_7_0_,
       qualificat2_.Description                                                                   as Descript5_7_0_,
       qualificat2_.QualificationAreaExpirySettingId                                              as Qualific6_7_0_,
       qualificat2_.DisplayOrder                                                                  as DisplayO7_7_0_,
       qualificat2_.DateCreated                                                                   as DateCrea8_7_0_,
       qualificat2_.DateUpdated                                                                   as DateUpda9_7_0_,
       qualificat2_.ShowOnSignupForm1                                                             as ShowOnS10_7_0_,
       qualificat2_.ShowOnSignupForm2                                                             as ShowOnS11_7_0_,
       qualificat2_.ShowOnSignupForm3                                                             as ShowOnS12_7_0_,
       qualificat2_.AgencyId                                                                      as AgencyId7_0_,
       qualificat3_.QualificationLevelId                                                          as Qualific1_47_1_,
       qualificat3_.Name                                                                          as Name47_1_,
       qualificat3_.Description                                                                   as Descript3_47_1_,
       qualificat3_.DateCreated                                                                   as DateCrea4_47_1_,
       qualificat3_.DateUpdated                                                                   as DateUpda5_47_1_,
       qualificat3_.AgencyId                                                                      as AgencyId47_1_,
       dbo.IsQualificationLevelAssociatedWithAnyQualifications(qualificat3_.QualificationLevelId) as formula21_1_
FROM   Qualification this_
       inner join QualificationArea qualificat2_
         on this_.QualificationAreaId = qualificat2_.QualificationAreaId
       inner join QualificationLevel qualificat3_
         on this_.QualificationLevelId = qualificat3_.QualificationLevelId
WHERE  this_.QualificationAreaId in (1 /* @p0 */,2 /* @p1 */,3 /* @p2 */)
       and this_.QualificationLevelId in (1 /* @p3 */,2 /* @p4 */,3 /* @p5 */)

To me, this logic seems flawed, it’s performing seperate “In” queries for each of the composite key ids; wouldn’t this return incorrect results?

For reference, I have .Equals and .GetHashCode properly implemented on my key class, so I’m sure that’s not the issue.

  • 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-15T20:31:18+00:00Added an answer on May 15, 2026 at 8:31 pm

    yes it will return wrong results, any of the pairs defined the composite-id values passed can evaluate to true, so while you request for example [ [1,1], [2,2], [3,3] ] this query will also fetch [ [1,2], [1,3], [2,1] [2,3], [3,1], [3,2] etc]..

    the only solution i can think now is a disjunction of the pairs… eg

    (this_.QualificationAreaId = 1 AND this_.QualificationLevelId = 1) OR

    (this_.QualificationAreaId = 2 AND this_.QualificationLevelId = 2) OR

    (this_.QualificationAreaId = 3 AND this_.QualificationLevelId = 3)

    etc….

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am doing a simple coin flipping experiment for class that involves flipping a
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns 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.