Hi all,
I am having problems with the Generics feature of the following
http://www.ayende.com/projects/nhibernate-query-analyzer/generics.aspx
My problem concerns specifically a many to many problem but may also affect one to many. I have a class called FileAsset which has a relationship with a collection of parameters. I have defined this relationship as follows:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="orange.core.domain.Asset, orange.core" table="Asset" proxy="orange.core.domain.Asset, orange.core" discriminator-value="0">
<cache usage="read-write"/>
<id name="Id" column="Id" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">orange_assetid_seq</param>
</generator>
</id>
<discriminator column="AssetType" type="Int32"/>
<property name="Name" column="Name" type="String" length="250"/>
<property name="Display" column="Display" type="Boolean"/>
<property name="InsertTimestamp" column="inserttimestamp" type="DateTime"/>
<bag name="AssetItems" cascade="all">
<!--inverse="true" lazy="true" order-by="Id">-->
<cache usage="read-write"/>
<key column="AssetId"/>
<one-to-many class="orange.core.domain.AssetItem, orange.core"/>
</bag>
<subclass name="orange.core.domain.ImageAsset, orange.core" discriminator-value="1" proxy="orange.core.domain.ImageAsset, orange.core"/>
<subclass name="orange.core.domain.FlashAsset, orange.core" discriminator-value="2" proxy="orange.core.domain.FlashAsset, orange.core">
<bag name="InternalParameters" cascade="all" table="AssetParameter" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics">
<cache usage="read-write" />
<key column="AssetId" />
<many-to-many class="orange.core.domain.Parameter, orange.core" column="ParameterId" outer-join="true"/>
</bag>
</subclass>
</class>
</hibernate-mapping>
Here is the parameter class:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="orange.core.domain.Parameter, orange.core" table="Parameter" proxy="orange.core.domain.Parameter, orange.core">
<cache usage="read-write"/>
<id name="Id" column="Id" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">parameter_assetid_seq</param>
</generator>
</id>
<timestamp name="UpdateTimestamp" column="updatetimestamp" />
<property name="Name" column="Name" type="String" length="100" />
<property name="ParameterValue" column="ParameterValue" type="String" length="100" />
</class>
</hibernate-mapping>
The article seems to imply that this relationship needs to be maintained on both sides. I don’t want the parameter objects to know anything about their parents because they could be different types.
The sample uses the constructors like so:
_blogs = new EntitySet<Blog>(
delegate(Blog b) { b.Users.Add(this); },
delegate(Blog b) { b.Users.Remove(this); },
InitializeOnLazy.Always);
I don’t want the Parameter object to have a reference to the FileAsset.
Is this possible using the Generics feature??
Could anyone send me any sample code if they have any??
Thanks