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).
Try this…