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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:24:55+00:00 2026-05-18T10:24:55+00:00

my application has 2 entities called Event and Transaction. An Event may or may

  • 0

my application has 2 entities called Event and Transaction. An Event may or may not have a transaction but can only have 1 Transaction. I thought the best way to map this was with a HasOne mapping. So far everything is fine but i want to make sure that when you delete an Event it won’t delete it if has a Transaction.

Normally on a HasMany relationship i would just set an Inverse and change Cascade to None. While Cascade exists, Inverse doesn’t and the event deletes regardless of whether it has a Transaction or not.

I’d appreciate it if someone could show me the correct way of doing this. 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-18T10:24:56+00:00Added an answer on May 18, 2026 at 10:24 am

    You could always create your own custom delete behaviour using a DeleteEventListener:

    public class DeleteEventListener : DefaultDeleteEventListener
      {
        protected override void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities)
        {
          Event event = entity as Event;
          if (event != null && event.Transaction != null) throw new Exception("You can't delete this Event! Look! It has a Transaction!");
          CascadeBeforeDelete(session, persister, entity, entityEntry, transientEntities);
          CascadeAfterDelete(session, persister, entity, transientEntities);
        }
      }
    

    This DeleteEventListener would then need to be registered as part of your NHibernate setup configuration. Within the session factory element:

    <event type="delete">
    <listener class="myNamespaces.DeleteEventListener, myAssembly" />
    </event> 
    

    I haven’t tested this particular code but I have similar code in my app so I can help out if you get stuck.

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

Sidebar

Related Questions

Application has an auxiliary thread. This thread is not meant to run all the
My application has just started exhibiting strange behaviour. I can boot it through the
I have an application in mind which dicates database tables be append-only; that is,
My iOS Application has been in review, but was rejected regarding the iOS Data
I have about 10 different entities in my J2EE application that right now share
In my application I have 2 entities that are defined as: public class A
My application has the following entities: public class User { public virtual int UserID
I have a WCF client which passes Self-Tracking Entities to a WPF application built
I have an application architecture which has following layers (or c# projects). web front
I have a Silverlight application that uses RIA Services. One of the entities is

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.