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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:31:32+00:00 2026-06-15T11:31:32+00:00

What would be the syntax in an nhibernate (version 3.3) query (criteria?) for the

  • 0

What would be the syntax in an nhibernate (version 3.3) query (criteria?) for the following SQL statement:

SELECT DISTINCT usr.* FROM User usr, User_SecurityGroup grp, SecurityGroup_Permission prm, Permission org 
WHERE usr.Id = grp.User_id AND grp.SecurityGroup_id = prm.SecurityGroup_id AND org.Id = prm.Permission_id 
AND org.Site_id IN (1,2,3) AND org.PermRead = 1 AND usr.Active = 1 AND org.Active = 1;

I am unsure how the joins would be done between the tables and the criteria syntax to complete such a task.

For this particular query, the list of Site ids will be passed in

Also the condition “org.PermRead = 1”, the property name will be dynamic. so it could be “PermWrite”.

Edit:
Ok so this is what I have so far

        ICriteria criteria = this.Session.CreateCriteria<User>();

        criteria.Add(Restrictions.In("User.Site", siteList.ToArray()));
        criteria.Add(Restrictions.Eq("User.Active", true));
        criteria.Add(Restrictions.Eq("Site.Active", true));
        criteria.Add(Restrictions.Eq(Enum.GetName(typeof(Perm.Types), access), true));

        criteria.SetResultTransformer(Transformers.DistinctRootEntity);
        return criteria.List<User>();

I think a join would be in a format like this:

        criteria.CreateAlias("Sites", "Sites", NHibernate.SqlCommand.JoinType.LeftOuterJoin); 
  • 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-15T11:31:33+00:00Added an answer on June 15, 2026 at 11:31 am

    I ended up with this:

           ICriteria criteria = Session.CreateCriteria<User>()
                .CreateAlias("SecurityGroups", "SecurityGroups")
                .CreateAlias("SecurityGroups.Permissions", "Permissions")
                .Add(Restrictions.Eq("Permissions.Active", true))
                .Add(Restrictions.Eq("Active", true))
                .Add(Restrictions.In("Permissions.Site", ids.ToArray()))
                .Add(Restrictions.Eq("Permissions.Perm" + Enum.GetName(typeof(Perm.Types), accessRight), Perm.Level.Allow));
            return criteria.List<User>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have the following syntax: python utility.py file1 FILE1 file2 FILE2
I would like to be able to support the following Sybase 15 ASE syntax
Why does the following query fails on MySql? NHibernate: INSERT INTO UserSetting (userId, key,
I am trying to reproduce a query using the Nhibernate Criteria API and cannot
I want to create an alias for a class name. The following syntax would
I have a query like below select f.id, s.name, ss.name from first f left
It's a subjective question but don't you think the following HTML syntax would make
The blog post introducing the new syntax said that the old MLish syntax would
If there were such a thing I would imagine the syntax to be something
Can anyone tell me why this would generate a syntax error in Safari and

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.