Skip to content

Not able to use SubclassMap with Join using Fetch.Subselect #738

Open
@ameysar

Description

@ameysar

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions