I'm trying to select an entity and fetch a related list:
Session.QueryOver<UserRole>()
.Fetch(x => x.UsersInRole).Eager
.List();
Which results in a lot of database hits. The first one is something like:
SELECT ... FROM UserRoles left outer join UsersInRoles on ...
And hundreds more seperate queries which looks something like:
SELECT ... FROM UsersInRoles left outer join UserRoles on ... WHERE UserRoles.UserId=?
The mapping is as following:
public class UserRoleMap : ClassMap<UserRole>
{
public UserRoleMap()
{
Id(x => x.Id);
Map(x => x.RoleName);
HasManyToMany(x => x.UsersInRole)
.Inverse()
.LazyLoad()
.Table("UsersInRoles");
}
}