NHibernate Orchard mapping problem / bug for 1-N relations

Topics: Core, Customizing Orchard, Troubleshooting, Writing modules
Mar 7, 2013 at 9:50 AM
Edited Mar 7, 2013 at 8:20 PM
Working on many 1-N relations between parts like order-orderdetail pricelist-price product-price, etc, I discovered what seems to be an incoherence in the way the orchard mapper is working.

Let's say I have an OderPartRecord and an OrderDetailPartRecord with corresponding OrderPart and OrderDetailParts.

in my OrderDetailPartRecord, I have a property
    public virtual OrderPartRecord Order { get; set; }
in my migration file I simply define the Order_Id column as
        SchemaBuilder.CreateTable("OrderDetailPartRecord", t => t
and with this when I get my OrderDetail part with contenmanager, NHibernate automatically fills the contained OrderPartRecord using the Order_Id.

This is ok and the same schema work OK for many others 1-N


if in my OrderPartRecord class I defined this property
    public virtual IList<OrderDetailPartRecord> Details { get; protected set; }
expecting Orchard+Nhibernate automatically filling the list when I get the OrderPart, it seems that the mapping created is trying to use a column named OrderPartRecord_Id, and not the Order_Id created to have the OrderPartRecord loaded in the OrderDetailPart object.
And I use the Column name 'OrderPartRecord_Id' in place of 'Order_Id' in migration and table creation, the OrderPartRecord is no more ok when I get the OrderDetailPart.....

If I open the mappings.bin file (and regenerate it to be sure it is last version) I see that the 2 mappings are generated, one using Order_Id and the other OrderPartRecord_Id ????

Is there a problem of circular reference and should we use either the parent record in the child, either the list of child records in the Parent BUT NOT THE 2 SIMULTANEOUSLY ?
Looks like a bug ?