locked
how to get student courses from many to many relationship RRS feed

  • Question

  • User939559474 posted

    hi everybody

    i'm using many to many relation ship in code first entity framework

    and i wanna to get courses of studentID

    i used this code

     var ItemEntity = uof.Courses.List(i => i.Students.FirstOrDefault().StudentID==StudentID && i.DelFlag == DelFlag).OrderBy(d => d.Title)

    but this get first course of studentID , iwanna get all courses of studentID

    any ideas 

    thanks,

    Monday, November 11, 2013 8:34 PM

Answers

  • User697462465 posted

    Hi haitham,

    Please change your code as below:

    var ItemEntity = uof.Courses.Where(i => i.Students.FirstOrDefault().StudentID==StudentID && i.DelFlag == DelFlag).OrderBy(d => d.Title).Select(s => s.StudentID);
    

    If your problem still exists, please let me know.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 13, 2013 2:40 AM

All replies

  • User939559474 posted

    need this please

    Monday, November 11, 2013 11:15 PM
  • User-330204900 posted

    You would get more milage posting in the MSDN Entity Framework Forums not the Dynamic Data forum, but if you can post your model or a link to an image of the relavent talbe I will try to help.

    Tuesday, November 12, 2013 4:38 AM
  • User939559474 posted

    pease help me in my code

    it's clear

    how to get courses within studentid

    thanks

    Tuesday, November 12, 2013 1:41 PM
  • User697462465 posted

    Hi haitham,

    Please change your code as below:

    var ItemEntity = uof.Courses.Where(i => i.Students.FirstOrDefault().StudentID==StudentID && i.DelFlag == DelFlag).OrderBy(d => d.Title).Select(s => s.StudentID);
    

    If your problem still exists, please let me know.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 13, 2013 2:40 AM