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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:00:13+00:00 2026-05-31T21:00:13+00:00

SQL Server: Table Name : Dad Fields: Id Table Name : Mom Fields: Id

  • 0

SQL Server:

Table Name : Dad
Fields: Id

Table Name : Mom
Fields: Id

Table Name: Child
Fields: Id, IdDad, IdMom

Child Check Constraint: IdDad is not null or IdMom is not null

NHibernate mapping class

public class ChildBase
{
    public int Id { get; set; }
}

public class DadChild : ChildBase
{
    public int IdDad { get; set; }
}

public class MomChild : ChildBase
{
    public int IdMom { get; set; }
}

public class Dad
{
    public int Id { get; set; }

    // Cascade = All, Table = "Child", ColumnKey = "Id"
    public IList Children { get; set; }

}

If i have in Dad object a Children collection with 3 Children i remove and delete the children

foreach (Child child in Dad.Children)
{
    child.Delete();
}

Dad.Children.Clear();

Data.Flush();

i get the constraint violation error because when trying to remove the children from Dad, the constraint says that the Child table cannot have IdDad and IdMom at null.

NHibernate try to do an update like this:

Update Child set IdDad = null where Id = xxx

As IdMom is currently null, can’t be IdDad and IdMom null, how can i delete from NHibernate the children collection?

-EDIT-

<class name="Dad, MyAssembly" table="Dad" lazy="true">
    <id name="Id" access="property" column="Id" type="Int32" unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <bag name="Children" access="property" table="Child" lazy="true" cascade="all" >
      <key column="IdDad" />
      <one-to-many class="Child, MyAssembly" />
    </bag>
</class>
  • 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-31T21:00:14+00:00Added an answer on May 31, 2026 at 9:00 pm

    You should use inverse="true" on your collection mapping if you wish to delete the entities in this manner.

    <bag name="Children" access="property" inverse="true" table="Child" lazy="true" cascade="all" >
      <key column="IdDad" />
      <one-to-many class="Child, MyAssembly" />
    </bag>
    

    Inverse Attribute in NHibernate

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

Sidebar

Related Questions

Microsoft SQL Server seems to check column name validity, but not table name validity
I have a sql server table with 2 fields, ID (primary key) and Name
We have a SQL Server table containing Company Name, Address, and Contact name (among
I am trying to save html table to sql server table with unique name
The SQL Server (2000/2005) function gets the table name and the field name as
I'm trying to use a dynamically generated fully-qualified table name in sql server 2008.
MS SQL Server 2000 I have a column in Table A called Name. I
I have a table called 'Audit' in SQL Server 2005 like this: Name |
I have an SQL Server table Table_1 with name, subname, value columns For each
I need help with SQL Server Table Column. I´m trying to rename Column Name,

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.