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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:51:34+00:00 2026-06-05T07:51:34+00:00

I have a class which is a child of 2 parents. When I delete

  • 0

I have a class which is a child of 2 parents.
When I delete one of the parents, I expect the children to be deleted, but the other parent keeps them in the session with an error Deleted object would be resaved by cascade

class Company
{
    // automap.HasMany(x=>x.Cars).Cascade.AllDeleteOrphan();
    IList<Car> Cars { get; set; }

    // automap.HasMany(x=>x.Employees).Cascade.AllDeleteOrphan();
    IList<Employee> Employees { get; set; }
}

class Employee
{
    // automap.references(x=>x.job);
    Company job { get; set; }

    // automap.hasMany(x=>x.OwnedCars).Cascade.AllDeleteOrphan();
    IList<Cars> OwnedCars { get; set; }
}

class Car
{
    // automap.references(x=>x.company)
    Company company { get; set; }

    // automap.references(x => x.Employee)
    Employee Driver {get; set; }  // might be null
}

When I remove an employee – i want his car to be removed from the company too;

var Company = Sesion..Get(1);
Company.Employees.removeAt(1); 
Session.Update(Company);

Is there a better way to do the removal rather then traverse the list of cars, chech whether the car has belonged to the Employee I’m removing – and remove the car too before removing the employee ?

  • 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-06-05T07:51:36+00:00Added an answer on June 5, 2026 at 7:51 am

    you will have to remove the association to the car from both the employee (maybe not necessary, as the employee will be deleted) and the company. So your delete would look like this:

    var company = session.Get(1);
    var employee = company.Employees[1];
    foreach(var car in employee.OwnedCars)
    {
        car.company.Cars.Remove(car);
    }
    company.Employees.Remove(employee);
    session.Update(company);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a situation where you have a parent class which has one child class,
I have a parent class which contains a child object. I am using set
I have a MustInherit Parent class with two Child classes which Inherit from the
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I have a class Child which does not have a ParentId property but has
ORMs often map one-to-many relationships such as: class Parent { IList<Child> Children { get;
I have a class which has a collection public class Parent { ... ISet<Child>
I have a templated class Child which inherits from a non-templated Parent class. When
I have written a base class from which I wish to derive several child
I have class which have one public method Start , one private method and

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.