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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:58:58+00:00 2026-05-12T09:58:58+00:00

I’ve got to classes Product and Store which have many to many relation I

  • 0

I’ve got to classes Product and Store which have many to many relation

I want deleting of store not to cause deleting of related product
And deleting of product not to cause deleting of related store.

Currently deleting of entity cause exception due to Foreign Key constraint.

Here is this classes and their mapping in fluent hibernate:

public class Product
{
    public Product()
    {
        this.StoresStockedIn = new List<Store>();
    }


    public virtual string Name { get; set; }

    public virtual double Price { get; set; }

    public virtual long ProductID { get; set; }

    public virtual IList<Store> StoresStockedIn { get; set; }

}

public class Store
{
    public Store()
    {
        this.Products = new List<Product>();
        this.Staff = new List<Employee>();

    }

    public virtual string Name { get; set; }
    public virtual IList<Product> Products { get; set; }
    public virtual IList<Employee> Staff { get; set; }
    public virtual long StoreID { get; set; }
}

public class ProductMap : ClassMap<Product>
{
    public ProductMap()
    {
        this.Id(x => x.ProductID);
        this.Map(x => x.Name);
        this.Map(x => x.Price);
        this.HasManyToMany(x => x.StoresStockedIn)
            .Cascade.None()
            .Table("StoreProduct");
    }
public class StoreMap : ClassMap<Store>
{
    public StoreMap()
    {
        this.Id(x => x.StoreID);
        this.Map(x => x.Name);
        this.HasManyToMany(x => x.Products)
            .Cascade.None()
            .Inverse()
            .Table("StoreProduct");
        this.HasMany(x => x.Staff)
            .Cascade.All()
            .Inverse();
    }
}

Thanks,
Alexey Zakharov

  • 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-12T09:58:58+00:00Added an answer on May 12, 2026 at 9:58 am

    if you choose to set the Cascade parameter at NONE, it’s up to you to manage this relation and so to put the store property value in the product to null before deleting the store. Like Karl said often you come with another class (association class) to hold additionnal information about the relation.

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

Sidebar

Related Questions

No related questions found

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.