This is a question related to another one I asked that was specific to NHibernate
, but I'm starting to think that my question might be far more fundamental than that.
ForNHibernate
-related reasons, I have a base abstract class (Listing
) and classes that inherit from it (Listing_UK
, Listing_US
, etc).
These are functionally identical.
I understand why this does not work:
List<Listing> test = new List<Listing_UK>();
Right now I'm doing the equivalent of this:
List<Listing> test = new List<Listing>();
test.Add(new Listing_UK() as Listing);
which works, but I need the classes to be more interchangeable, like the above.
I appreciate that the fundamental idea behind what I'm doing is a little weird, but does anyone have any advice?
EDIT:
I've clearly made my examples way too abstract.
I was trying to avoid making this too NHibernate
-specific so that it's actually different from my other question (and because I think what I'm asking is more fundamental), but what I basically want to achieve is this:
IQueryOver<Listing,Listing> test = null;
if(condition) {
test = DBSession.QueryOver<Listing_UK>();
} else {
test = DBSession.QueryOver<Listing_US>();
}
test.Where(l => l.Field == "value").List<Listing>();
From the reactions I am getting here, I'm reasonably sure that what I'm asking for is not possible.