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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:41:28+00:00 2026-05-29T14:41:28+00:00

I have an object hierarchy as follows: Object Reports Report Items Based on other

  • 0

I have an object hierarchy as follows:

  • Object
    • Reports
      • Report Items

Based on other posts here, I set the Report.ReportItems mapping to Inverse, and CascadeAllDeleteOrphan. This makes it so when I remove a Report from an Object it goes to erase the ReportItems in that report.

The way it does it is very inefficient. It basically does a Delete ... Where ReportItemID = ?.

I’ve seen suggestions to increase the batch size to prevent this from being done in too many round trips, but that seems like a sloppy fix. Is there a way to make NHibernate generate a query like this instead:

Delete ... Where ReportID = ?

This way it would execute one query that would delete all the ReportItems instead of one statement per ReportItem.

Thanks in advance.

Edit

I have heard from a few people that NHibernate will simply not work this way with standard QueryOver etc.

I decided to start using HQL to fix the problem. I will later use some reflection to make sure there are no “magic strings” being used.

I had the idea to:

  1. Use HQL to mass-delete the Report Items
  2. Tell the Session to Refresh the object so it could detect that the Report Items are gone
  3. Then tell the session to erase the Report, and let it clean up the remaining information

This does not work though. You can see the code below:

Session.CreateQuery("delete ReportItem r where r.Report= :report").SetEntity("report", SelectedReport).ExecuteUpdate()
Session.Refresh(SelectedReport)
Object.Reports.Remove(SelectedReport)
Session.Delete(SelectedReport)
Session.Update(Object)

I have also tried doing a Session.Evict after performing the HQL statements, but NHibernate keeps using the cache to try to delete the ReportItems. Any tips on how to do this?

  • 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-29T14:41:29+00:00Added an answer on May 29, 2026 at 2:41 pm

    After a lot of research I have found that this is simply not possible. You can use HQL, raw SQL statements, or rely on database rules to perform the deletes by enforcing a relationship. However, there is no way to tell NHibernate to delete a list of objects based on their owner’s ID.

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

Sidebar

Related Questions

I have a winforms TreeView control that allows you to browse an object hierarchy.
I have a domain object hierarchy with a top level abstract class. In GORM,
I have an object hierarchy public class MyBase {} public class MyDerived : MyBase
I have a simple object hierarchy, and I want to query each of the
I have object , tree/model/hierarchy, whatever the correct term is. It consists of what
I have an 3 object hierarchy which has a root as 'Division' that has
I have this XML that I am trying to read into an object hierarchy:
I have hierarchy of classes like follows (in fact I have more than 3
I have an object hierarchy similar to the following: interface IVideoStream { } abstract
Problem: I have the object hierarchy A => B => C - that's A

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.