0

I have a S table. It can have some Children. The Children are same type(S).

Table : S(Id,Name)

Table : S_R(Parent_S_Id,Child_S_Id)

Classes are

public class S
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<S> Children { get; set; }

    public S()
    {
        this.Children = new List<S>();
    }

    public virtual void AddChildren(S s)
    {
        this.Children.Add(s);
    }
}

public class SMap : ClassMap<S>
{
    public SMap()
    {
        Table("S");

        Id(x => x.Id, "Id").GeneratedBy.Increment();
        Map(x => x.Name, "Name");

        HasManyToMany<S>(x => x.Children)
            .Table("s_r")
            .ParentKeyColumn("S_ID")
            .ChildKeyColumn("CHILD_S_ID")
            .Cascade.All()
            .LazyLoad()
            .Inverse();
    }
}

but it doesn't work. It is not saving relation in relation table. Could anyone have any idea and view. Please share your view and suggestion.

Jugal Panchal
  • 1,448
  • 16
  • 20

1 Answers1

1

remove the Inverse() from the HasManyToMany because it tells NHibernate that the other side should maintain the association entries, but there is no other side.

Firo
  • 30,626
  • 4
  • 55
  • 94