Here is an interesting problem that pop up with any OR/M that supports inheritance and lazy loading.
Let us say that we have the following entity model:
Backed by the following data model:
As you can see, we map the Animal hierarchy to the Animals table, and we have a polymorphic association between Animal Lover and his/her animal. Where does the problem starts?
Well, let us say that we want to load the animal lover. We do that using the following SQL:
And now we have an animal lover instance:
var animalLover = GetAnimalLoverById(1); var isDog = animalLover.Animal is Dog; var isCat = animalLover.Animal is Cat;
Can you guess what would be the result of this code?
I’ll post the actual answer tomorrow…