Hi!

I'm currently doing my first steps with NHibernate. So far, I've set
up a database with the tables "Users", "Roles" and "UserRoles". My
mapping looks like this:

  <class name="User" table="Users">
    <id name="Id">
      <generator class="guid" />
    </id>

    <property name="Login" not-null="true" />
    <property name="PasswordSha1" not-null="true" />

    <set name="Roles" table="UserRoles" lazy="false">
      <key column="UserId" />
      <many-to-many class="Role" column="RoleId" />
    </set>
  </class>

So any user can have a 0 or more roles, and roles can be shared
amongst many users (in short, an m:n relationship). If I query the
users, this works nicely with lazy loading enabled:

  return Session.CreateCriteria<User>()
    .List<User>();

Returns 8 users, including the "Administrator" user which has 4 roles
assigned. However:

  return Session.CreateCriteria<User>()
    .SetFetchMode("Roles", FetchMode.Eager)
    .List<User>();

Returns 11 users - there are 4 copies of the "Administrator" user,
each with one role.

Am I doing something wrong? Or is NHibernate not understanding its own
left/right join?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to