Fluent NHibernate Many-to-Many

后端 未结 4 1366
暗喜
暗喜 2020-12-14 01:56

I am using Fluent NHibernate and having some issues getting a many to many relationship setup with one of my classes. It\'s probably a stupid mistake but I\'ve been stuck fo

4条回答
  •  独厮守ぢ
    2020-12-14 02:40

    You have three tables right?

    People, Groups, and GroupAdministrators

    when you add to both sides you get

    People (with an id of p1) Groups (with an id of g1)

    and in GroupAdministrators you have two columns and a table that has

    (p1,g1)

    (p1,g1)

    and your unit test code looks like the following.

    Context hibContext //Built here
    Transaction hibTrans //build and start the transaction.
    
    Person p1 = new Person()
    Groups g1 = new Groups()
    
    p1.getGroupsOwned().add(g1)
    g1.getAdmins().add(p1)
    
    hibTrans.commit();
    hibContext.close();
    

    And then in your test you make a new context, and test to see what's in the context, and you get back the right thing, but your tables are all mucked up?

提交回复
热议问题