Search code examples
nhibernateormfluent-nhibernatenhibernate-mappingfluent-nhibernate-mapping

Delete in HasManyToMany


I have three table - 1. Anomaly 2. Markup 3. Anomaly_Markup

Mapping -

    public AnomalyMap()
    {
        Table("anomaly");

        Id(x => x.Id).Column("ID").CustomType("decimal");

        HasManyToMany<DMMarkupData>(x => x.DMMarkupData)
            .Table("anomaly_markup")
            .ParentKeyColumn("ANOMALY_ID")
            .ChildKeyColumn("MARK_UP_ID")
            .Cascade.All()
            .LazyLoad();
    }

    public MarkupDataMap()
    {
        Table("markup");
        Id(x => x.Id).Column("ID");
    }

Condition :

  1. Save data by Anomaly - Anomaly contains MarkupData. It saves data. It is working functionality with me.
  2. Delete markup - which should delete relationship from map table and markup data. I am facing this issue.

Anyone help me to find out solution, how to delete markup data ?


Solution

  • I see no relationship of MarkUpData with Anomaly. There must be same relationship and you should specify the control of cascade operation by using Inverse attribute in your mapping. You can refer : How to set "cascade delete" option to "Set Null" in Fluent NHibernate?

    To delete DMMarkupData just remove the object from collection and call for Save Anomaly.