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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:57:49+00:00 2026-05-30T11:57:49+00:00

I have been working on a many to many mapping on an entity i

  • 0

I have been working on a many to many mapping on an entity i have called Task. A task can have many children and many parents. There is a join table in between which just has the two FK columns “ParentTaskId” and “ChildTaskId”. Here is what I have come up with so far.

        // Many-to-Many Parents
        HasManyToMany<Task>(x => x.Parents)
            .Table("TaskDependency")
            .ParentKeyColumn("ParentTaskId")
            .ChildKeyColumn("ChildTaskId")
            .Inverse()
            .Not.LazyLoad()
            .Cascade.SaveUpdate();

        // Many-to-Many Children
        HasManyToMany<Task>(x => x.Children)
            .Table("TaskDependency")
            .ParentKeyColumn("ChildTaskId")
            .ChildKeyColumn("ParentTaskId")
            .Not.LazyLoad()
            .Cascade.SaveUpdate();

And here is some example code to help me illustrate my question. The code below works:

        _taskRepository.Save(_taskVendor);
        _taskRepository.Save(_taskClientVendor);
        _taskRepository.Save(_taskClient);

        _taskVendor.Children.Add(_taskClientVendor);
        _taskClientVendor.Children.Add(_taskClient);
        _taskRepository.Save(_taskVendor);
        _taskRepository.Save(_taskClientVendor);

        _taskRepository.Delete(_taskVendor);
        _taskRepository.Delete(_taskClientVendor);
        _taskRepository.Delete(_taskClient);

But if I change the order of the delete statements to be:

        _taskRepository.Delete(_taskVendor);
        _taskRepository.Delete(_taskClient);
        _taskRepository.Delete(_taskClientVendor);

I get a fk constraint violation on my many to many join table. I think this has to do with the way I have inverse set up on my mapping. It effects the order in which queries are executed to avoid this exact fk constraint issue. Is there any way to map this so that I could delete entities on either side, child or parent, without having this exception? I tried inverse on both sides of my mapping but that just resulted in my many to many relationship not getting saved. >_<

Any help would be much appreciated.

  • 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-30T11:57:51+00:00Added an answer on May 30, 2026 at 11:57 am

    you have to remove them manually

    void Delete(Task task)
    {
        foreach (var parent in task.Parents)
        {
            parent.Childs.Remove(task);
        }
        session.Delete(task);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with WebServices for sometime. I dealt with many services where
I have been working on a childish little program: there are a bunch of
I have been working on many applications which run as windows service or scheduled
I have been working with IE6 for many years [sob], but have never seen
I have been working on this issue for a few days now and can't
I have been working on this problem for quite some time and can't figure
I have been working on a project recently where a Player can create a
Hi For many days I have been working on this problem in MySQL, however
I have been working with Monodroid for a few days and still can't figure
I have been working with C# for many years, since beta. I am having

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.