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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:01:57+00:00 2026-05-18T02:01:57+00:00

I have 3 classes like: public class Animal { … all sort of data

  • 0

I have 3 classes like:

public class Animal
{
   ... all sort of data ...
}

public class Cat : Animal
{
   ... more data ...

   public virtual int Size { get; set; }
}

public class Dog : Animal
{
   ... other data ...

   public virtual int Size { get; set; }
}

The classes are mapped using the “table per hierarchy” strategy in the hbm.xml mapping the Cat’s Size property is mapped to a CatSize column and the Dog’s property to DogSize

The following two queries work as expected:

From Cat o Where o.Size = 1
From Dog o Where o.Size = 1

Now I want to query Animal for all the cats where Size = 1 and all the dogs where size = 1, combining the two queries above I get:

From Animal Where o.Size = 1 Or o.Size = 1

That obviously doesn’t do what I want, how can I tell NHibernate the first Size is Cat.Size and the second is Dog.Size (preferably without knowing the column names in the database).

Note: I understand the design is problematic an having two properties with the same name in different subclasses is not the smartest design decision ever made – but changing it now is even more problematic and I’d like to avoid it (the project should be delivered to the client in a few days and I really don’t want to make design changes now).

I’m using NHibernate 2.0.1 (upgrading is not an option, the program does not work with later versions of NHibernate and we don’t have time to fix it now).

  • 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-18T02:01:58+00:00Added an answer on May 18, 2026 at 2:01 am

    Try this…

    select a from Animal a where a in (select c from Cat c where c.Size = 1) or a in (select d from Dog d where d.Size = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes layed out like this class A { public virtual void
I have something like the following classes: public class Animal { ... } public
I have a hierarchical data classes like public class MyNode { public string Name
I have Java classes like this: public class Config { public Config1 getConfigOpt1(); public
Say I have classes declared like this: public abstract class IdentifiableEntity { public boolean
Lets say I have a two classes like this: public class LocalResources { public
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have a base class vehicle and some children classes like car, motorbike etc..
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have a set of core, complicated JavaScript data structures/classes that I'd like 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.