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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:36:51+00:00 2026-05-22T12:36:51+00:00

I have a one-many relation: Object ReportCategory: Table("RCA_REPORT_CATEGORY"); Id(r => r.Id, "RCA_ID"); Map(r =>

  • 0

I have a one-many relation:

Object ReportCategory:

Table("RCA_REPORT_CATEGORY");
    Id(r => r.Id, "RCA_ID");
    Map(r => r.Name, "RCA_NAME");
    HasMany<Report>(r => r.Reports)
        .Table("REP_REPORT")
        .KeyColumns.Add("REP_RCA_ID").Cascade.None();

Object Report:

Table("REP_REPORT");
        Id(r => r.Id, "REP_ID");
        Map(r => r.Name, "REP_NAME");
        References(r => r.Category, "REP_RCA_ID")
            .Cascade.None();

There is a foreign key on REP_REPORT.REP_RCA_ID which references RCA_REPORT_CATEGORY.RCA_ID.

When I delete a ReportCategory which has a Report, it works and the REP_RCA_ID column in the Report Table is set to NULL.
But I don’t want that. I want an exception to be thrown and tell me that the category can’t be deleted because it is used by a report and it violate the foreign key constraint. How can I achieve that?

  • 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-22T12:36:51+00:00Added an answer on May 22, 2026 at 12:36 pm

    Make Category reference not nullable:

    Table("REP_REPORT");
            Id(r => r.Id, "REP_ID");
            Map(r => r.Name, "REP_NAME");
            References(r => r.Category, "REP_RCA_ID")
                .Not.Nullable()
                .Cascade.None();
    

    Then the database column REP_RCA_ID cannot be NULL and attempt to delete not-empty category will lead to SQL exception. Such case should be avoided in your domain model first and the exception from db should be throwed only when there is a bug in your application.

    Maybe you should mark HasMany collection as inverse to avoid some troubles:

    Table("RCA_REPORT_CATEGORY");
        Id(r => r.Id, "RCA_ID");
        Map(r => r.Name, "RCA_NAME");
        HasMany<Report>(r => r.Reports)
            .Table("REP_REPORT")
            .Inverse()
            .KeyColumns.Add("REP_RCA_ID").Cascade.None();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-to-many relation between Parent and Child table. In the parent object
I have a many-to-many relation on a single object with itself: <set name=relatedPersons lazy=false
I have a question about Criteria method, one-to-many relation to the database, 'one' is
I have multiple level parent-child tables(GrandParent, Parent and Child, all many to one relation,
I have the following model: One name (Char) Many one (ForeignKey,blank=True,null=True) title (Char) I
I have the following one-to-many relation between two objects. Parent --> IList<Child> Now, I
I have objects A witch has many to many relation ship to object b.
I have a object (Book) with a many-to-many relation with another object (Category). 'Category'
I am trying to get a One-To-Many relation working. I have the following mappings:
I have many to one relation, let's say User has a Company. Company entity

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.