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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:43:30+00:00 2026-05-17T06:43:30+00:00

I have an issue when deleting a child record from the session. Here are

  • 0

I have an issue when deleting a child record from the session. Here are the entities i have defined:

public class ReportedData
{
    public virtual int ReportedDataID { get; set; }
    public virtual ReportedDataTypes Type { get; set; }
    public virtual string Reason { get; set; }

    public virtual IList<ArticleCommentReported> ArticleCommentsReported { get; private set; }
    public virtual IList<ForumPostReported> ForumPostsReported { get; private set; }

    public ReportedData()
    {
        ArticleCommentsReported = new List<ArticleCommentReported>();
        ForumPostsReported = new List<ForumPostReported>();
    }
}

public class ArticleCommentReported : ReportedData
{
    public virtual ArticleComment Comment { get; set; }
}

public class ForumPostReported : ReportedData
{
    public virtual ForumPost Post { get; set; }
}

With the following fluent mapping:

public ReportedDataMap()
{
    Table("ReportedData");
    Id(x => x.ReportedDataID);
    Map(x => x.Type, "TypeID");
    Map(x => x.Reason);
    HasMany(x => x.ArticleCommentsReported)
        .KeyColumn("ReportedDataID")
        .Inverse()
        .Cascade.All();
    HasMany(x => x.ForumPostsReported)
        .KeyColumn("ReportedDataID")
        .Inverse()
        .Cascade.All();
}

public class ArticleCommentReportedMap : SubclassMap<ArticleCommentReported>
{
    public ArticleCommentReportedMap()
    {
        Table("ArticleCommentsReported");
        KeyColumn("ReportedDataID");
        References(x => x.Comment, "CommentID");
    }
}

public class ForumPostReportedMap : SubclassMap<ForumPostReported>
{
    public ForumPostReportedMap()
    {
        Table("ForumPostsReported");
        KeyColumn("ReportedDataID");
        References(x => x.Post, "PostID");
    }
}

Now say i try the following (i have added comments to help you understand what’s going on):

// Loop over the reported data (this is my view model and not my actual model which contains an extra property for the action they wish to carry out)
foreach (var reportedData in model)
{
    // If the action is leave then do nothing (else we always delete the reported data)
    if (reportedData.Action != ReportedDataActions.Leave)
    {
        // Switch over the type since we need to make sure it deletes the article comment or post if the action is set to delete
        switch (reportedData.Type)
        {
            case ReportedDataTypes.ArticleComment:
                var reportedComment = _context.Repository<ArticleCommentReported>().GetByID(reportedData.ReportedDataID);

                if (reportedData.Action == ReportedDataActions.Delete)
                    _context.Repository<ArticleComment>().Delete(reportedComment.Comment);

                _context.Repository<ArticleCommentReported>().Delete(reportedComment);

                break;
            case ReportedDataTypes.ForumPost:
                var reportedPost = _context.Repository<ForumPostReported>().GetByID(reportedData.ReportedDataID);

                if (reportedData.Action == ReportedDataActions.Delete)
                    _forumService.DeletePost(reportedPost.Post);

                _context.Repository<ForumPostReported>().Delete(reportedPost);

                break;
        }
    }
}

_context.Commit();

When the user trys to delete a forum post (the Action against the reported data is set to delete) it throws the following error:

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [ForumPostReported#2]

I could probably set some mapping up to automatically delete the post/comment once the reported data is deleted but i only want to delete the post/comment if the action is set to delete.

I’d appreciate it if someone could help. Thanks

  • 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-17T06:43:30+00:00Added an answer on May 17, 2026 at 6:43 am

    Problem solved! I just had to delete the reported item first. Seems kinda backwards but it works and that’s all i care.

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

Sidebar

Related Questions

Have an issue with marshall and unmarshall readers and writers. So here it is.
I have an issue of alphabetically sorting the contacts picked from the address book
I have an issue while getting the file name with out extension from a
I have an issue. I am getting data from a MySQL database, and make
I have a slight issue in my C# code in Asp.net when deleting a
I have an issue in my program when I'm deleting the 2d-pointer-array. I did
I have an issue when it comes to deleting a file . I have
I have an issue here, I'm not sure if it's possible but I would
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So

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.