'Inheritance Mapping Fluent NHibernate results in unnecessary joins

The issue is when selecting directly on the base model the generated SQL performs an left outer select on the subclasses.

Basemodel.

public class Node
{
   public virtual int ID {get;set;}
   public virtual string Url {get;set;}
}

public class CMSPage : Node
{
   public virtual string FieldA {get;set;}
   public virtual string FieldB {get;set;}
}

public class Article : Node 
{
   public virtual string FieldC {get;set;}
   public virtual string FieldD {get;set;}
}

My Mapping is

public class NodeMap : ClassMap<Node>
{
   Table("Nodes");
   Id(x => x.ID, "Node_ID");
   Map(x => x.Url);
}    

public class CMSPageMap: SubclassMap<CMSPage>
{
   Table("CMSPages");
   Map(x => x.FieldA);
   Map(x => x.FieldB);
}    

public class ArticleMap: SubclassMap<Article>
{
   Table("Articles");
   Map(x => x.FieldC);
   Map(x => x.FieldD);
}    

When querying direct on Nodes using ICriteria

  var store = session.CreateCriteria(typeof(Node));           
  store.Add(Restrictions.Eq("Url", filter.Url));                
  store.SetProjection(Projections.ProjectionList()
   .Add(Projections.Property("ID"), "ID")                   
   .Add(Projections.Property("Url"), "Url"));                
  store.SetResultTransformer(new 
  AliasToBeanResultTransformer(typeof(Node)));
  Node result = store.UniqueResult<Node>();

The sql generated is

SELECT this_.Node_ID     as y0_, this_.Url         as y7_ FROM   Nodes this_
   left outer join CMSPages this_1_
   on this_.Node_ID = this_1_.Node_ID
   left outer join Articles this_2_
   on this_.Node_ID = this_2_.Node_ID
WHERE  this_.Url = '/' /* @p0 - Url */

How do i prevent the join selects

Ive tried using both Abstract and KeyColumn according to https://www.codeproject.com/Articles/232034/Inheritance-mapping-strategies-in-Fluent-Nhibernat



Sources

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

Source: Stack Overflow

Solution Source