I have posted this question on Stack Overflow (http://
stackoverflow.com/q/8235629/61654) but wanted to see if I could get
more attention here.


The following class maps setup the relationship between
AbstractWorkflowRequestInformation and IRequest. The map for
AbstractWorkflowRequestInformation is pretty vanilla while the map for
IRequest is a bit more involved. IRequest utilizes several
SubclassMaps.

The below mappings work but cause an issue when retrieving multiple
instances of AbstractWorkflowRequestInformation. Each instance
retrieval does a select from workflow_request_information joined to a
sub query which selects from each sub class table via a union all.
Again this works but joined select is not limited by the
workflow_request_information_id and therefore is equivalent to doing a
select * for each instance of AbstractWorkflowRequestInformation.

To better illustrate here is a representative example of the sql that
is generated to get associated IRequest instances whenever I retrieve
an AbstractWorkflowRequestInformation instance. Assume that the select
* are actually specific columns from each table.

    select *
      from (select *
              from plan_request
            union all
            select *
              from bnj_request)
     where workflow_request_information_id = 123

Essentially the sub query is doing unconstrained query of every
IRequest record which is incredibly slow as the number of records
grows. Preferably the sub query would be limited by the
workflow_request_information_id and would look something like this:

    select *
      from (select *
              from plan_request
             where workflow_request_information_id = 123
            union all
            select *
              from bnj_request
             where workflow_request_information_id = 123)

What do I need to do to my maps to force this change to the generated
sql? Essentially is there a way to limit the joined sub query by the
id of a particular AbstractWorkflowRequestInformation?

**IRequestMap**

    public class IRequestMap : ClassMap<IRequest>
    {
        public IRequestMap()
        {
            HasOne(x => x.WorkflowRequestInformation).Constrained();
            Id(x =>
x.WorkflowRequestInformationId,"workflow_request_information_id")
                .GeneratedBy.Foreign("WorkflowRequestInformation");
            UseUnionSubclassForInheritanceMapping();
        }
    }

    public class PlanRequestMap : SubclassMap<PlanRequest>
    {
        public PlanRequestMap()
        {
            Table("plan_request");
            // specific to PlanRequest property mappings and
references
        }
    }

    public class BnjRequestMap : SubclassMap<BnjRequest>
    {
        public BnjRequestMap()
        {
            Table("bnj_request");
            // specific to BnjRequest property mappings and references
        }
    }

**AbstractWorkflowRequestInformationMap**

    public class AbstractWorkflowRequestInformationMap :
        ClassMap<AbstractWorkflowRequestInformation>
    {
        public AbstractWorkflowRequestInformationMap()
        {
            Table("workflow_request_information");
            Id(x => x.Id)
                .Column("workflow_request_information_id")
                .GeneratedBy.Identity();

            HasOne<IRequest>(x => x.Request).Cascade.All(); //
reference to IRequest
            // more property mappings and references
        }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to