Suppose I have the following scenario:
I have offerblocks which contain one or more offeritems.
Each offeritem can be in any offerblock.
So I'm thinking many-to-many.
I created tables like this:
OfferBlock (id, name)
OfferBlock_OfferItem (offerblockId, OfferItemId)
OfferItem (OfferItemId, offerprice, etc)
This all works fine with the following mapping:
Code:
<bag name="OfferItems" table="OfferBlock_OfferItem">
<key column="OfferBlockId" />
<many-to-many column="OfferItemId" class="OfferItem, Namespace" />
Now the change request:People want to be able to SORT the offerItems in the block. So that particular offeritems go first when a block with items gets loaded.
So I'm thinking add a SortOrder column (int) in the OfferBlock_OfferItem table.
I can change my mapping for OfferBlock like this:
...
Code:
<bag name="OfferItems" table="OfferBlock_OfferItem" order-by="SortOrder DESC">
<key column="OfferBlockId" />
<many-to-many column="OfferItemId" class="OfferItem, Namespace" />
Works like a charm when I load the OfferBlock with Nhibernate! Because the offerItems are indeed sorted on the SortOrder column!
Now the problem:
In my database I have the three tables. But in my code I only have two classes (OfferBlock with an IList<OfferItem> and the OfferItem class)
Where or how should I add the SortOrder column as a field to my code-classes ??
Thanks,