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 3362080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:13:47+00:00 2026-05-18T03:13:47+00:00

having a little trouble with a mapping for the following table setup currently: Shop

  • 0

having a little trouble with a mapping for the following table setup currently:

               Shop
             [1]  [1]                 
            /       \
          [n]       [n]
   Category-[m]---[n]-Article

The behaviour should be the following :
1 – when deleting a shop, all Articles and Categories Should be deleted
2 – when deleting a Category, related Articles should be unassigned but not deleted
3 – when deleting an Article, related Categories should be unassigned but not deleted

Here’s the current mapping:

public class ShopMap: ClassMap<Shop>
{
    public ShopMap()
    {
        this.Table("shop");
        Id(x => x.Id).Column("id").GeneratedBy.Native();
        Map(x => x.Name).Column("name");

        HasMany(x => x.Categories).Cascade.AllDeleteOrphan;
        HasMany(x => x.Articles).Cascade.AllDeleteOrphan;
    }
}

public class CategoryMap: ClassMap<Category>
{
    public CategoryMap()
    {
        this.Table("category");
        Id(x => x.Id).Column("id").GeneratedBy.Native();
        Map(x => x.Name).Column("name");

        References(x => x.Shop);

        HasManyToMany(x => x.Articles).Cascade.AllDeleteOrphan()
                                    .Table("article_category")
                                    .ChildKeyColumn("article_id")
                                    .ParentKeyColumn("category_id")
                                        .Inverse();
    }
}

public class ArticleMap: ClassMap<Article>
{
    public ArticleMap()
    {
        this.Table("article");
        Id(x => x.Id).Column("id").GeneratedBy.Native();
        Map(x => x.Name).Column("name");

        References(x => x.Shop);

        HasManyToMany(x => x.Categories).Cascade.All()
                                    .Table("article_category")
                                    .ParentKeyColumn("article_id")
                                    .ChildKeyColumn("category_id");
    }
}

When deleting a Category (Session.Delete()), NH tries to delete the related Articles as well. Changing the Cascade-Mode to SaveUpdate will fix this, but will leave the entries in the link table *article_category*. Summing up : Cascade.SaveUpdate is too lazy, Cascade.All is too eager.

I tried everything that came to my mind in the mappings, but couldn’t find a correct way to map this (rather simple schema).

Any ideas on how to (fluently) map this are greatly appreciated!

Thanks in advance

Sebi

  • 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-18T03:13:48+00:00Added an answer on May 18, 2026 at 3:13 am

    The entries are left in the link table because Category.Articles is defined as the inverse side of the relationship. You need to remove the Category from Article.Categories before deleting it in order for the link record to be removed.

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

Sidebar

Related Questions

I'm having a little trouble with this. First of all, this is for a
I'm having a little trouble putting a JQuery accordion into a site. I feel
I am having a little trouble retrieving the values from a JSON object that
I'm having a little trouble getting localized resources files to work on Windows Phone
I'm having a little trouble building the grids for a Battleship game for my
I am having a little trouble with parsing XML from a google checkout response.
I am having a little trouble getting this to work. I have several anchor
I'm writing a little Symbian app and I'm having troubles with QDataWidgetMapper. This is
I'm using nHibernate on a webpage for viewing items from an already existing database.

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.