I am pretty new to nhibernate and have been tinkering more and more
lately.  I've run into an issue with a <list /> mapping.

Here is my mapping file (taken from the Customer -> Order -> LineItem)
example in the nhibernate docs

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyProject.Model" namespace="MyProject.Model">
  <class name="Order" table="Orders">
    <id name="Id">
      <generator class="identity" />
    </id>
    <property name="OrderDate" />
    <many-to-one name="Customer" column="CustomerId" />
    <list name="OrderLineItems" table="OrderLineItems" lazy="true">
      <key column="OrderId" />
      <index column="OrderLineItemNumber" />
      <composite-element class="OrderLineItem">
        <property name="Quantity" column="Quantity" />
        <many-to-one name="Product" column="ProductId" />
      </composite-element>
    </list>
  </class>
</hibernate-mapping>

I see the appropriate SQL being run
NHibernate: SELECT order0_.Id as Id3_0_, order0_.OrderDate as
OrderDate3_0_, order0_.CustomerId as CustomerId3_0_ FROM Orders
order0_ WHERE order0_....@p0; @p0 = '1'

NHibernate: SELECT orderlinei0_.OrderId as OrderId0_,
orderlinei0_.Quantity as Quantity0_, orderlinei0_.ProductId as
ProductId0_, orderlinei0_.OrderLineItemNumber as OrderLin4

The second SELECT returns 2 rows which I would expect.  But when I try
to iterate through the Order.OrderLineItems collection property there
are 3 in the collection.  The first item is null.

I've got the follow property on my Order class

public virtual IEnumerable<OrderLineItem> OrderLineItems { get; set; }

I am unsure as to what I am missing here.  Is an empty OrderLineItem
initialized?

Any help would be appreciated.

Thanks.

--~--~---------~--~----~------------~-------~--~----~
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