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

  • Home
  • SEARCH
  • 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 8473181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:16:41+00:00 2026-06-10T17:16:41+00:00

I have Orders, Items and OrderItems entities with n:n relationship between Orders and Items

  • 0

I have Orders, Items and OrderItems entities with n:n relationship between Orders and Items table. I am using Fluent Hibernate for mapping, in “Order” entity there is “List” property which has “protective set”. I am facing below problem, while inserting.

new Order.Items.Add(alreadyexistingitem);

Since its already existing item, in the orderitems table, a record needs to be inserted into orderitems table with new orderid and existing item id. But only new order details are inserted in order table not in associative table.

“Inverse” attribute is set for “items” bag in orders entity. So, I need to attach the newly added order while adding item like below but how can i do it as it is the list object with protective set.

Orders.Items.Add(alreadyexistingitem, *order = "neworder"*);

Below is the mapping:

   model.Override<Order>(m =>
   {      

                    m.HasManyToMany(c => c.Items)
                        .Table(Constants.TABLE_PREFIX + "OrderItem")
                        .Inverse()
                        .Cascade.AllDeleteOrphan();
    });



  model.Override<Item>(m => m.HasManyToMany(c => c.Orders)
                                            .Table(Constants.TABLE_PREFIX + "OrderItem")
                                            .Cascade.None());
  • 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-06-10T17:16:44+00:00Added an answer on June 10, 2026 at 5:16 pm

    As a preliminary answer, NHibernate is smart enough to know when the same object reference is being used in two places. All you should need is a “HasManyToMany” relationship in the mapping between Order and Item.

    Inverse should probably not be used on the orders side. Inverse tells NHibernate that the opposite side of the relationship has the power to define and break the relationship. Orders have items; items don’t get to “choose” what order they belong to.

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

Sidebar

Related Questions

[NOTE: I'm using ASP.NET MVC2 RC2.] I have URLs like this: /customers/123/orders/456/items/index /customers/123/orders/456/items/789/edit My
I have problem with items order in legend, when I using Google Chrome browser
I have a typical model setup: Store has_many Items Orders has_many Items :through OrderItems
I have a table of orders. Each order is linked to one or more
Suppose say I have Order, Items, OrderItems tables with Order and Items having n:n
I have an Order mapping with many OrderItems. The mapping correctly saves both the
I have a database the have orders, and which order many order items, that
I have a many-to-many relationship between two tables: Order and Item. I need to
Here's what I'm trying to do: I have Orders, OrderItems, and Vendors. Each Order
I have a private class variable that holds a collection of order items: Private

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.