'Calling stored procedure on Inherited class in [Fluent] NHibernate without discriminators

I have a working Fluent project with some inherited tables

class Base { int BaseId }
class Derived : Base {}
class Derived2 : Base {}

class BaseMap : ClassMap<Base> { ID BaseId ); }
class DerivedMap : SubclassMap<Derived> { Id( BaseId ); }
class DerivedMap2 : SubclassMap<Derived2> {Id( BaseId ); }

These tables do not have a dedicated "discriminator" column, NHibernate just figures it out.

I've noticed that the SQL queries it runs, even if I specifically request a Base entity, it will join to all subclasses, add a CASE statement with a parameter named clazz, and use that to return a proxy with the extended objects available (so it knows if there is a 'derived2' in existence and will just give me that). This all works fine...

Problem

I have an existing stored procedure that returns records from Base. I'm trying to call this via CreateSqlQuery like so:

Session.CreateSQLQuery( "exec SP_GetAllFromBase" )
       .AddEntity( nameof( Base ) )
       .List<Base>();

But when I try to map it an entity type of Base, I get an IndexOutOfRange exception as NHibernate tries to find a clazz property in the returned result set (just like it adds onto all its own queries...). But the stored procedure is just returning rows from Base and not adding a special case statement to the end.

Is there is way I can tell CreateSqlQuery that it specifically needs to return a Base instance and not Derived?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source