1

I have a many-to-many relation between Course and Group entities

Course (1:n) Course-Group (n:1) Group

  • Course(Name,CourseGroups of type Course-Group ...)
  • Group(Name,GroupsCourses of type Course-Group...)
  • Course-Group(Course,Group,...)

I want to select Course and related Course-Group and Group

This is my query

QueryOver.Of<Course>().JoinQueryOver<Course-Group>(c => c.CourseGroups).Fetch(cf=>CourseGroups).Eager
.JoinQueryOver<Group>(cg => cg.Group).**[Fetch(cg => cg.Group).Eager.]**
DetachedCriteria

C# Compiler report error for section in the bracket

How can I query a many-To-many relation as above?

Eranga
  • 32,181
  • 5
  • 97
  • 96

2 Answers2

0

if you just want to fetch them eagerly

var query = QueryOver.Of<Course>()
    .Fetch(c => c.CourseGroups).Eager
    .Fetch(c => c.CourseGroups.Group).Eager;

otherwise there's only subqueries, see here why

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94
0

You have to future in the collections you want otherwise you'll end up with Cartesian products. See this link for more information about what that looks like: https://stackoverflow.com/a/5683564/764805

Community
  • 1
  • 1
Fourth
  • 9,163
  • 1
  • 23
  • 28