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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:49:41+00:00 2026-05-19T06:49:41+00:00

I did some searching on this and didn’t turn up anything. Is it possible

  • 0

I did some searching on this and didn’t turn up anything. Is it possible to create a Hibernate query to return a set of objects based on a discriminator?

I have an AbstractUser class which is extended by the concrete classes UserTypeA and UserTypeB. I’m using the table-per-hierarchy model to map my classes in NHibernate, so UserTypeA and UserTypeB are both stored in the same table with different discriminator values. Here is my discriminator mapping property:

<discriminator column="Type" type="string"/>

I have a column in my table that contains the name of the user type. I’m wondering if it’s possible to run a NHibernate query using this.

I tried this:

public IList<DomainBase> FindByType(string typeName, Type type)
{
    string query = "from " + type.Name + " k where k.Type = " + typeName;
    return Session.CreateQuery(query).List<DomainBase>();
}

But since Type is not actually a property of the class, just a column in the table, this obviously doesn’t work. It would seem redundant to have both a property for this purpose and a discriminator, unless there’s a way to use a property as a discriminator?

  • 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-19T06:49:43+00:00Added an answer on May 19, 2026 at 6:49 am

    Actually, this is well documented at http://www.nhibernate.info/doc/nh/en/index.html#queryhql-where:

    Likewise, the special property class
    accesses the discriminator value of an
    instance in the case of polymorphic
    persistence. A .Net class name
    embedded in the where clause will be
    translated to its discriminator value.

     from Eg.Cat cat where cat.class = Eg.DomesticCat
    

    You can also pass a System.Type instance as a parameter.

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

Sidebar

Related Questions

I did some searching and didn't find a question that directly answered this question.
I did some fairly thorough reading and searching through SO and didn't find anything
My apologies if this has been answered before or is obvious...did some searching here
First of all, I did some searching for an answer to this question...but I
Somewhat new to php, I did some searching but didn't find a clear answer.
Apologies if this was answered elsewhere -- I did some searching and couldn't find
I did some searching and was not able to find any information regarding this
I did some searching on this site and on google as well. But i
I'm guessing this has been asked before, but I did some searching and haven't
Apologies if this has been asked before, but I did some searching and wasn't

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.