How to match a custom NHibernate collection with fluentNHibernate?

I try to display a collection for two days without success. I also read all the possible articles and forums, but still there. So here is the problem:

1) The collection class contains the private field "_internalCollection", which is displayed by NHIB.

2) The holding entity must set read-only data collection property.

3) I want to avoid implementing the NHibernate IUserCollectionType interface !!!

I did this with xml rendering and it works great. The WarehouseEntity element is a collection element. Warehouses are a readonly property in the OrgEntity class.

<component name="Warehouses" class="Core.Domain.Collections.EntitySet`1[Core.Domain.OrgStructure.IWarehouseEntity,Core],Core"> <set name="_internalCollection" table="`WAREHOUSE`" cascade="save-update" access="field" generic="true" lazy="true" > <key column="`WarehouseOrgId`" foreign-key="FK_OrgWarehouse" /> <!--This is used to set the type of the collection items--> <one-to-many class="Domain.Model.OrgStructure.WarehouseEntity,Domain"/> </set> </component> 

Any idea how I can do this with fluent NHibernate?

EDIT: Core.Domain.Collections.EntitySet`1 is the base class. It provides basic functions for working with collections and can correspond to any class that is an IEntity interface.

+2
collections nhibernate fluent-nhibernate nhibernate-mapping
source share
1 answer

Try:

 HasMany(x => x.Warehouses) .AsSet().KeyColumn("WarehouseOrgId") .Access.CamelCaseField(Prefix.Underscore) .ForeignKeyConstraintName("FK_OrgWarehouse"); 

Edit: I missed the key part of the question, so another try:

 Component(x => x.Warehouses, m => { m.HasMany<Warehouse>(Reveal.Member<EntitySet<IWarehouseEntity>>("_internalCollection") .AsSet().KeyColumn("WarehouseOrgId") .ForeignKeyConstraintName("FK_OrgWarehouse"); }); 

I am sure that is not this, but hopefully this puts you on the right track. Also see ComponentMap .

My advice is to completely abandon user collections. I replaced all of our extension methods with IEnumerable<T> .

+3
source share

All Articles