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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:21:31+00:00 2026-05-24T17:21:31+00:00

I have a problem that is driving me crazy. I’ve been searching around and

  • 0

I have a problem that is driving me crazy. I’ve been searching around and found some possible solutions, but none with any result. I’ll try to explain as good as I can.

I have two models, PostModel (parent) and CommentModel (child). For better understanding, my mapping looks like this:

Mapping for Post:

public class PostMap : ClassMap<PostModel> 
{
    public PostMap()
    {
        // Table
        Table("Post");

        // Relations
        HasMany<CommentModel>(o => o.Comments).KeyColumn("PostId").Inverse().Cascade.AllDeleteOrphan();
    }
}

Mapping for comment:

public class CommentMap : ClassMap<CommentModel> 
{
    public CommentMap()
    {
        // Table
        Table("Comment");

        // References
        References<PostModel>(o => o.Post).Column("PostId");
    }
}

Now, what I’m trying to do is to delete a comment entity from post like this:

public void DeleteComment(CommentModel commentToDelete) 
{
    // Delete from list
    commentToDelete.Post.Comments.Remove(commentToDelete);

    // Update parent
    Update(commentToDelete.Post);
}

The result? Nothing is happening. Nothing is deleted from the list, no exceptions or what so ever. Does anyone have a solution for this, or any thoughts? I really appreciate all help I can get.

TIA!

  • 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-24T17:21:32+00:00Added an answer on May 24, 2026 at 5:21 pm

    If you set Inverse() you will have to update your comment

    I suggest this approach:

    public void DeleteComment(CommentModel commentToDelete) 
    {
        // Delete from list
        commentToDelete.Post.Comments.Remove(commentToDelete);
    
        // This is needed because the Comments is an Inverse collection
        commentToDelete.Post = null;
    
        // Update parent
        Update(commentToDelete.Post);
    
        // Delete the comment
        Delete(commentToDelete);
    }
    

    If you always remove your associations in both objects, you should not have problems.

    You can also remove the Inverse

    HasMany<CommentModel>(o => o.Comments).KeyColumn("PostId").Cascade.AllDeleteOrphan();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey! Have a problem that is driving me crazy! My Main Window will not
I'm having a problem lately that's driving me crazy. I have a multi-dimensional array
I have a problem with an ASP.NET application that is driving me nuts. When
(I have a problem that I illustrated in this question but had no correct
I have a question that is driving me crazy. It is all about updating,
I have the following problem in application express which is driving me crazy: I
I have a simple yet hard problem here that is driving me nuts ...
I'm running into a little problem that's driving me crazy, and I'd welcome any
Okay, I'm not doing anything fancy here, but it's driving me crazy that I
I have been going crazy over a problem with my tab control. It has

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.