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

The Archive Base Latest Questions

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

Having a really hard time trying to figure out a where in equivalent in

  • 0

Having a really hard time trying to figure out a “where in” equivalent in nHibernate.

I am using nHibernate 3. What’s the best way to do something like this:

SELECT DISTINCT                                     
    U.ID as CID                         
FROM User U
WHERE                                               
CID IN (                                            
    SELECT RID                                      
    FROM ResellerSites rs                           
    INNER JOIN Locations l ON l.ID = rs.LID         
    WHERE   l.ID        =   14          
) 

I found an examples somewhere that says I need to have something like this:

var criteria = session.CreateCriteria(typeof(User));

var resellerSites = new[] { new ResellerSite { Id = 1 }, new ResellerSite { Id = 2 } };
criteria.Add(new InExpression("ResellerSite", resellerSites));

This is what I have so far:

     var resellerSites = session.CreateCriteria<ResellerSite>("p")
                        .CreateCriteria("p.Locations", JoinType.InnerJoin)
                        .Add(Restrictions.Eq("locationID", locationId))
                        .List<ResellerSite>();

     criteria.Add(new InExpression("ResellerSite", resellerSites));

     var finalList = criteria.List<ResellerSite>();

The “criteria.Add(new InExpression” part is giving me an intellisense error, as InExpression seems to expect something like:

 new[] { new ResellerSite { Id = 1 }, new ResellerSite { Id = 2 } };

Like in the first example.

Should I do a for loop like:

foreach (var site in resellerSites)
{
    //somehow push into a  new[] ?
}

or something like that or is there a better way?

Perhaps this entire approach is wrong?

  • 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-31T11:15:27+00:00Added an answer on May 31, 2026 at 11:15 am

    I’d say that the typing problem comes from the double CreateCriteria and the single ToList()

    Difficult to say without the table definitions, but, rereading you code, I wonder why you need the inner join with the locations.
    May be you can rewrite your query as :

    SELECT DISTINCT                                     
        U.ID as CID                         
    FROM User U 
        INNER JOIN ResellerSites rs
           on U.ID = rs.RID
           and rs.LID=14
    

    And have your code like (not tested and not optimal as you could have only one criteria query with join)

    var resellerSites = session.CreateCriteria<ResellerSite>()
                        .Add(Expression.Eq("locationID", locationId))
                        .List<ResellerSite>();
    
     criteria.Add(new InExpression("ResellerSite", resellerSites.ToArray()));
    
     var finalList = criteria.List<ResellerSite>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really having a hard time trying to figure out what's going on here.
I am having a really hard time trying to get this to work. All
I am trying to best figure out a way to store this particular case
I'm having a really hard time figuring out the scoping issue with the following
I am new to iPhone programming and am having a really hard time trying
I'm having a really hard time when trying to cancel requests in an NSOperationQueue.
I am having a really hard time attempting to debug LINQ to SQL and
I am having a really hard time reconciling IoC, interfaces, and events. Let's see
I'm having a really hard time understanding delegates and object inheritance (if I may
I just start playing with GWT I'm having a really hard time to make

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.