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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:50:06+00:00 2026-05-18T04:50:06+00:00

I am using the latest Nhibernate and i have a linq query to return

  • 0

I am using the latest Nhibernate and i have a linq query to return just 1 column. so I can’t use for example IQueryable as there is no entity class – i am returning only 1 column. But return to IQueryable Non Generic version doesn’t provide the ToList method

Here is the method

    public IQueryable GetCode()
    {
        using (ITransaction transaction = _session.BeginTransaction())
        {

            var results = (from c in _session.Query<Client>()
                           select new
                           {
                               Group = c.Code
                           }).Distinct();

        }
    }

Of course if i do this (see below) i get the ToList method on my IQueryable

    public IQueryable<Client> GetCode()
    {
        using (ITransaction transaction = _session.BeginTransaction())
        {

            var results = (from c in _session.Query<Client>()
                           select c;

        }
    }

The problem being is that i need to do DISTINCT and use only 1 column.

Any ideas, i am at a loss

Thanks in advance

EDIT

When i look at the type that is returned via IQueryable it is

{NHibernate.Linq.NhQueryable<<>f__AnonymousType6>}

and looking under the base class of what is returned i see an exception

Expression type 10005 is not supported by this SelectClauseVisitor.

  • 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-18T04:50:06+00:00Added an answer on May 18, 2026 at 4:50 am

    Wouldn’t the following work?

    public IQueryable<X> GetCode() // X = the type of Client.Code
    {
        using (ITransaction transaction = _session.BeginTransaction())
        {
    
            var results = (from c in _session.Query<Client>()
                           select c.Code).Distinct();
    
        }
    }
    

    The problem here is not just that you can’t call ToList on a non-generic IQueryable, but that the entire result is untyped, so you cannot read the Code property of each element either. (This can be worked around with C# 4’s dynamic type, but that’s not really what you want here.)

    In your case, I don’t see why you really need to construct an anonymous type just to return a distinct sequence of Code values renamed as Group. Returning the field’s value should be sufficient.

    If you’d need to return more than just one column, you should create an explicit type, rather than using an anonymous type, so you can say

    public IQueryable<ClientGroupAndSomething> GetCode()
    {
        using (ITransaction transaction = _session.BeginTransaction())
        {
    
            var results = (from c in _session.Query<Client>()
                           select new ClientGroupAndSomething
                           { 
                               Group = c.Code, 
                               ... 
                           }).Distinct();
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the latest nHibernate.Linq 2.1.2. But if I use join in my
I have this WPF application using NHibernate and lazy data loading. I also use
I'm using S#arpArchitecture (ASP.NET MVC and Fluent NHibernate). I have an entity as follows:
I have a SQL query I'm having trouble creating using NHibernate Criteria: SELECT ID,
I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite
I am using latest Pyramid to build a web app. Somehow we have started
I am using jQuery(Latest release) and have a function called calculate() which gets called
I have this nhibernate query: var q = NHibernateSession.Current.CreateSQLQuery ( @SELECT LastestEvents.* FROM (
I am attempting to use the Fluent-NHibernate automapping functionality (in the latest version of
I have a fluent nhibernate configuration in my app. Running latest of both. I

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.