0

Here is my class :

public class Course : BaseEntity
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public virtual int? TeacherId { get; set; }
        public virtual Teacher Teacher { get; set; }
        public virtual IList<CourseStudent> CourseStudents { get; set; } 
    }
}, 
 public class CourseStudent : BaseEntity
    {
        public virtual int CourseId { get; set; }
        public virtual Course Course { get; set; }
        public virtual int StudentId { get; set; }
        public virtual Student Student { get; set; }
    }
}

I defined COurse in Breeze Controler and this is show on my view, the name of course, teacher and Description but hot to show students for specific course.

tritop
  • 1,655
  • 2
  • 18
  • 30
smurf
  • 1
  • 1

1 Answers1

1

Use the "property path expand" query technique to eager load the each course's students:

http://www.breezejs.com/documentation/query-examples#PropertyPathExpand

the html/knockout bindings would look something like this:

<ul data-bind="foreach: courses">
   <li>
      <h1 data-bind="text: Name" />

      <ul data-bind="foreach: CourseStudents">
         <li data-bind="text: Student.Name" />
      </ul>   
   </li>
</ul>
Jeremy Danyow
  • 26,470
  • 12
  • 87
  • 133
  • [meta]i tried to expand but it doesn't work i'm doing something wrong here but i don't now what- this is my query in : var query = EntityQuery.from('Courses') .expand('Teacher','CourseStudent') .orderBy('name'); – smurf Aug 01 '14 at 11:45
  • missing 's': `.expand('Teacher', 'CourseStudent**s**')` – Jeremy Danyow Aug 01 '14 at 11:54
  • I've fixed this but it show "Unable to parse binding, refernece error", Here is my html :
    Name:
    Name of teacher:
    List of Students :
    And i use FOREACH also show the same error
    – smurf Aug 01 '14 at 12:04
  • And i really need help for this... pls help me – smurf Aug 01 '14 at 12:13
  • I think there are two issues: 1) improper capitalization in the bindings- for example `with: teacher` should be `with: Teacher` because the Course entity's 'Teacher' property name is capitalized. Same thing with the course name and student name bindings, etc. 2) I don't think the `text: Student.Name` binding will work unless you change the expand call in your query to `.expand('Teacher', 'CourseStudents.Student')` – Jeremy Danyow Aug 01 '14 at 12:14
  • No i use CamelCase and everything is show on a view the only problem is to show Students who learning in one course, i've fixed 'CourseStudents.Student' but again it's show the error in binding coursestudent. – smurf Aug 01 '14 at 12:22
  • camel case for the CourseStudents property would be 'courseStudents' (capitalize the s in student). – Jeremy Danyow Aug 01 '14 at 12:28
  • bummer. I can't move this discussion to a chat because your rep is below 20. What is the output of `JSON.stringify(course)` ? – Jeremy Danyow Aug 01 '14 at 13:02