Hi,
I am struggling a bit with a many-to-many relationship that has features.
Basically, I have a many-to-many relationship between items and squares - an
item can occur in many squares and a square can have many items. I had no
problems to implement this using NHibernate. However the requirements have
changed - items occur in squares depending on time (years). The relation
model should look like this (pseudo code):
Table Squares
(
SquareId int
...
)
Table Items
(
ItemId int
...
)
Table ItemsSquares
(
ItemId int,
SquareId int,
Year int
)
This mapping file snipped seems to create these tables:
<class name="Item" table="Items" optimistic-lock="version"
dynamic-update="true">
<id name="ItemId" unsaved-value="0">
<column name="ItemId" sql-type="bigint"/>
<generator class="identity" />
</id>
<set name="Squares" table="ItemsSquares" cascade="save-update">
<key column="ItemId"/>
<composite-element class="ItemSquare">
<parent name ="Item" />
<many-to-one name="Square"
class="Square"
column="SquareId"
not-null="true" />
<property name="Year">
<column name="Year" not-null="true" sql-type="int"/>
</property>
</composite-element>
</set>
</class>
<class name="Square" table="Squares">
<id name="SquareId" unsaved-value="0">
<column name="SquareId" sql-type="bigint"/>
<generator class="identity" />
</id>
</class>
Unfortunately, I have trouble at the 'usage site' (e.g. determine selected
squares for given itemid). Do I have to create a class ItemSquare with a
mapping similar to this:
<class name="ItemSquare" table="ItemsSquares">
<id name="ItemSquareId" unsaved-value="0">
<column name="ItemSquareId" sql-type="bigint"/>
<generator class="identity" />
</id>
<property name="Year">
<column name=" Year " not-null="true" sql-type="int"/>
</property>
<many-to-one name="Item" class="Item" column="ItemId" />
<many-to-one name="Square" class="Square" column="SquareId" />
</class>
Any feedback would be very much appreciated. Is anyone aware of a working
'many-to-many relationship example with features'?
Thanks,
Christian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---