Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:15:32+00:00 2026-05-13T09:15:32+00:00

how would I map this relationship in NHibernate (I’m using the simple idea of

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:15:33+00:00Added an answer on May 13, 2026 at 9:15 am

    I don’t see the problem. A user may make multiple bids, and there may be multiple bids on a single item. It’s pretty common in any real-world database for some tables to have more than one FK/relationship, and your mapping code looks right to me.

    (P.S. I’m assuming you also have your bags [or similar] in the Item and User maps… if that’s what you’re having a problem with, you should mention that specifically.)

    Edit: Actually there is one thing I would probably change, and that is the utility method itself. Normally you wouldn’t have a reason to put something like in the Item class, instead you would use the repository pattern, which wraps an ISession and has a method signature like:

    public void AddBid(User user, Item item, Decimal amount) ...
    

    Or maybe even:

    public void AddBid(Guid userID, Guid itemID, Decimal amount) ...
    

    You get the idea – the point is that the method isn’t attached to a specific entity, it’s attached to a unit of work. I find it to be a better design for the DAL, but it is just one way, and there’s really nothing wrong with yours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table structure and would like to map it using Fluent Hibernate
Recently I've found an example on NHibernate's one-to-many relationship. The mapping goes like this:
I'm working on a RoleProvider in .NET, using Fluent NHibernate to map tables in
I would like to implement a map simmilar to this: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/examples/advanced_example.html One of the
Assuming three tables which map a many to many relationship. People 1 Bob 2
How would you test this scenario? I've just started looking into NHibernate and having
I'm using nHibernate on a webpage for viewing items from an already existing database.
I would like to use NHibernate Automapper to map the following class: public class
I am having a problem trying to map out a many-to-many relationship , where
with Fluent NHibernate i can map a one to many relationship against my User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.