I'm new to Fluent NHibernate and working with databases in general, so I'm 
not sure what I should Google for. 
I have a many-to-many relationship (User HasManyToMany Departments). When I 
QueryOver User, I would like for the Departments to be loaded into 
User.Departments. What happens now if a user has multiple departments is I 
get two users back with the same IDs, but each has one department.

I would like my result to look like this:
UserA.Departments = ["Department1", "Department2"] // actual departments of 
the user.

But after my query, I get something like this:
[... {UserA.Departments=["Department1"]}, 
{UserA.Departments=["Department2"]} ... ]

I've attached my mappings and the query. If anyone can tell the name of 
what I'm trying to do, that would be awesome.


 public class UserEntityOverride : IAutoMappingOverride<UserEntity>
    {
        public void Override(AutoMapping<UserEntity> mapping)
        {
            mapping.HasManyToMany(x => x.Departments)
                   .Table("UserDepartment")
                   .ParentKeyColumn("UserId")
                   .ChildKeyColumn("DepartmentId")
                   .Cascade.AllDeleteOrphan();

            mapping.References(x => x.Supervisor);
            mapping.References(x => x.Building);
        }
    }

var query = QueryOver.Of<UserEntity>()
                     .Fetch(x => x.Building).Eager
                     .Fetch(x => x.Departments).Eager
                     .OrderBy(x => x.FirstName).Asc
                     .ThenBy(x => x.LastName).Asc;
var users = 
query.GetExecutableQueryOver(session).Future<UserEntity>().ToList();

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to