我正在尝试选择一个实体并获取相关列表:
Session.QueryOver<UserRole>()
.Fetch(x => x.UsersInRole).Eager
.List();
这会导致大量数据库命中。第一个是这样的:
SELECT ... FROM UserRoles left outer join UsersInRoles on ...
还有数百个单独的查询,看起来像:
SELECT ... FROM UsersInRoles left outer join UserRoles on ... WHERE UserRoles.UserId=?
映射如下:
public class UserRoleMap : ClassMap<UserRole>
{
public UserRoleMap()
{
Id(x => x.Id);
Map(x => x.RoleName);
HasManyToMany(x => x.UsersInRole)
.Inverse()
.LazyLoad()
.Table("UsersInRoles");
}
}