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.

4

1 回答 1

1

从 HasManyToMany 中删除 Inverse() 因为它告诉 NHibernate 另一方应该维护关联条目,但没有另一方。

于 2013-07-15T20:00:54.503 回答