Incoherence in Orchard NHibernate mapping for 1-N relations


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 Orchar+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.

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 SIMULTEOUSLY ?
This finally appeared to me as a bug and I opened this ticket.
Closed Apr 23, 2013 at 9:06 PM by sebastienros
In 1.x you should be able to change the default mapping conventions with the new events which will be provided by Piotr, next week (private joke). Though doing so will break most of the migrations which expect RECORD_id


CSADNT wrote Mar 7, 2013 at 11:19 AM

I forget to add that if I use the Column name OrderPartRecord_Id in place of Order_Id, the OrderPartRecord is no more ok when I get the OrderDetailPart.....

sebastienros wrote Apr 2, 2013 at 9:20 PM

I think the auto-mapping expects the property to be of the name of the class in the case of the reverted relationship.

So in OrderDetailPartRecord the property should be named OrderPartRecord.

CSADNT wrote Apr 3, 2013 at 9:26 AM

I tried, but in this configuration the 'Order' record does not get filled when I get the OrderDetail part. I will do another try to double check.

CSADNT wrote Apr 9, 2013 at 8:19 AM

Is there a way to change this default mapping, I tried to dive in the core data dealing with mapping but its clumsy and will need a long time to understand the design choices fixed in Orchard ?