I am trying a bunch of new (to me) feature of NHibernate and keep
running into problems. I am not sure whether this one is a bug or user
error, but when trying to eagerly fetch an entity with its collection
using the new Linq provider, I get what looks like a cartesian
product.

Parent entity -- "Operation":
public class Operation
{
  public virtual Guid Id { get { return _id; } }
  ...
  public virtual IList<OperationStep> Steps { get _steps; }
}

Child entity -- "OperationStep":
public abstract class OperationStep
{
  public virtual Guid Id { get { return _id; } }
  public virtual Operation Operation { get { return _operation; } }
  ...
}

public class InsertBatchStep : OperationStep
{
  ...
}

Linq query:
var operations = (from op in session.Query<Operation>
                         orderby op.DateCreated
                         select op).FetchMany(op =>
op.Steps).ToArray();

SQL:
select   operation0_.Id              as Id0_0_,
         steps1_.Id                  as Id1_1_,
         operation0_.DateCreated     as DateCrea2_0_0_,
         operation0_.Creator         as Creator0_0_,
         operation0_.Status          as Status0_0_,
         steps1_.OperationId         as Operatio3_1_1_,
         steps1_.StepOrder           as StepOrder1_1_,
         steps1_.ExecutionCount      as Executio5_1_1_,
         steps1_.DateOfNextExecution as DateOfNe6_1_1_,
         steps1_.DateOfLastExecution as DateOfLa7_1_1_,
         steps1_.Status              as Status1_1_,
         steps1_.LastError           as LastError1_1_,
         steps1_.Type                as Type1_1_,
         steps1_.OperationId         as Operatio3_0__,
         steps1_.Id                  as Id0__
from     [Operation] operation0_
         left outer join OperationStep steps1_
           on operation0_.Id = steps1_.OperationId
order by operation0_.DateCreated asc


The Operation database table contains one operation, and the
OperationStep table contains four steps. The query returns 4
operations objects, each with 4 steps.

Mappings:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="FabricController" namespace="FabricController">
        <class name="Operation" table="Operation">
                <id name="Id">
                        <generator class="guid.comb" />
                </id>

                <property name="DateCreated" 
access="nosetter.camelcase-underscore" /
>
                <property name="Creator" access="nosetter.camelcase-underscore" 
/>
                <property name="Status" access="nosetter.camelcase-underscore" 
/>

                <bag name="Steps" table="OperationStep" 
access="nosetter.camelcase-
underscore">
                        <key column="OperationId" />
                        <one-to-many class="OperationStep" />
                </bag>
        </class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="FabricController" namespace="FabricController">
        <class name="OperationStep" table="OperationStep">
                <id name="Id">
                        <generator class="guid.comb" />
                </id>

                <discriminator column="Type" />

                <many-to-one name="Operation" column="OperationId"
access="nosetter.camelcase-underscore" />

                <property name="StepOrder" 
access="nosetter.camelcase-underscore" />
                <property name="ExecutionCount" />
                <property name="DateOfNextExecution" />
                <property name="DateOfLastExecution" />
                <property name="Status" />
                <property name="LastError" />

                <subclass name="OperationSteps.ConfirmBatchIndexedStep">
                </subclass>

                <subclass name="OperationSteps.InsertBatchStep">
                </subclass>

                <subclass name="OperationSteps.LoadBatchDataStep">
                </subclass>

                <subclass name="OperationSteps.PurgeDataStep">
                </subclass>
        </class>
</hibernate-mapping>

So is this me? What am I doing wrong?

Thanks in advance!

-Michael

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to