Hi, how would I map this relationship in NHibernate (I'm using the simple idea of the auction example to demonstrate the problem)
Database Tables / Entities:
User - contains the users
Item - an item for sale (like ebay)
Bid - records a user's bid on an item
I was imagining the bid table to look like this with:
Id (PK), ItemId (FK), UserId (FK), Amount, TransactionDate
with a mapping file something like:
<class name="Bid">
<id name="Id" class="guid">
<generator class="guid.comb" />
</id>
<many-to-one
name="Item"
column="ItemId"
class="Item"
not-null="true" />
<many-to-one
name="User"
column="UserId"
class="User"
not-null="true" />
<property name="Amount" type="Double" not-null="true" />
<property name="TransactionDate" type="DateTime" not-null="true" />
</class>
In the code (vb.net sorry) if you added a simple convenience method it would look like this which seems no good:
Public Class Item
'...
Public Sub AddBid(ByVal bid as Bid, ByVal user as User)
bid.User = user
bid.Item = Me
Bids.Add(bid)
End Sub
End Class
But i'm thinking I must have this design wrong...i thought of using a composite key, but that seems more wrong...any help greatly appreciated!