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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:23:14+00:00 2026-05-22T21:23:14+00:00

I need to do a simple group by with a nhibernate query. My try

  • 0

I need to do a simple “group by” with a nhibernate query.

My try were :

(from adn in session.Query<Table>()
        orderby adn.Data
        select adn.Data).Distinct().ToList<string>();

and

 session.Query<Table().GroupBy(adn => adn.Data).Select(dat => dat).ToList<string>()

can someone help me to find a solution ?
My goal is to retrieve all the Distinct “Data” Column.
It can be by group by or distinct.

(the 2 solutions would be better for my progression in nhibernate)

Regards

edit

Danyolviax, I tryied your solution

        return (from adn in session.Query<Table>()
                group adn by adn.Data into dataGroupe
                select dataGroupe).ToList<string>();

It doesn’t work.
I feared that I use Nhibernate 3.1 (and not 2.1)

Any correction or alternative solution ?

edit 2

In the second solution which works (^^)

I have a list of a class with one property.
In my case, I prefer to have a list of string or int.
Otherwise I should create a specific class for this case.

Do you know a trick.

And thanks for your support.

  • 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-22T21:23:15+00:00Added an answer on May 22, 2026 at 9:23 pm

    Look here:

    Linq to NHibernate and Group By

    here some examples:

    http://msdn.microsoft.com/en-us/vcsharp/aa336754

    updated

    try this with 3.1.0.4000:

       var ret = (from adn in session.Query<Table>()
                  group adn by adn.Data into dataGroup
                  select new {dataGroup.Key }).ToList();
    

    update

    var ret = (from adn in session.Query<Table>()
               group adn by adn.Data into dataGroup
               select dataGroup.Key).ToList<string>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with a query. Consider the following table: I need to select
I need to CREATE a new table from a query on existing tables using
I need a simple table with a user name and password field in MySQL.
I really need a calculated column on a table with simple sum. Please see
I need to add a simple style to a Tableview based on a query
Many of the properties on my model need to be represented a simple group
I need to group by range of years starting from date of birth. This
Seemed like a simple problem, I need to extract a capturing group and optionally
What I need is such a simple, easy query, it blows me away how
a simple table contains - id , name , text . I need to

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.