I have removed this property, but am getting the same thing, a
NHibernate.Collection.Generic.PersistentGenericList<MyProject.Model.OrderLineItem>
collection that contains 3 items, with collection[0] being null.
I have gotten this to work using a <bag />
<bag name="OrderLineItems" table="OrderLineItems" cascade="none"
lazy="true">
<key column="OrderId" />
<composite-element class="OrderLineItem">
<property name="QuantityOrdered" column="QuantityOrdered" />
<many-to-one name="Product" column="ProductId" />
</composite-element>
</bag>
On May 15, 9:12 am, Fabio Maulo <[email protected]> wrote:
> Remove the property OrderLineItem.OrderLineItemNumber and try again.That
> property is auto-managed by NH using the position in IList (default based on
> 0).
> You can specify a different base.
>
> 2009/5/14 Grimley <[email protected]>
>
>
>
>
>
> > 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.
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---