fluent-nhibernate icon indicating copy to clipboard operation
fluent-nhibernate copied to clipboard

Not able to use SubclassMap with Join using Fetch.Subselect

Open ameysar opened this issue 8 months ago • 0 comments

I have a mapping for base class and derived

public class Document: ClassMap<Document>
{
    public Document()
    {
        Table("documents");

        // Mapping properties
        Id(x => x.Id)
            .Column("id")
            .GeneratedBy.Sequence("documents_sequence");

        DiscriminateSubClassesOnColumn("type");
    }
}

    public class Invoice: SubclassMap<Invoice>
    {
        public Invoice()
        {
            DiscriminatorValue((byte)DocumentType.Invoice);
            
            Join("invoice", join =>
            {
                join.KeyColumn("id");
                join.Fetch.Subselect();
                
                join.Map(x => x.SomeField)
                    .Column("some_field")
                    .Length(255)
                    .Not.Nullable();
            });

I use query to load documents

var partners = session.Query<Document>()
    .ToList();

If I use join.Fetch.Join(); it makes outer join for table invoice. In case join.Fetch.Select(); query will make multiple select for each "document.id". In case of multiple subclass tables it would be performance degradation for both Fetch.Join and Fetch.Select . What I need is doing subselect to load all invoiced by using base document select. How can I achive this ?

ameysar avatar Apr 01 '25 16:04 ameysar