2

i had type this linq query for my domain context but why it would failed to retrieve the data of both table matched student id in tblaptmt ?

    public IQueryable<StudentViewAppointment> StudentViewAppointments(string StuId)
    {
        //IQueryable<StudentViewAppointment> studentViewAppointments =
        //from aptmt in this.ObjectContext.tblaptmts join ch in
        //aptmt.consultationID equals ch.consultationID where aptmt.studentID == StuId
        //select aptmt;
        //return studentViewAppointments as IQueryable<StudentViewAppointment>;

        return ObjectContext.tblaptmts.Where(a => a.studentID == StuId).Join
        (ObjectContext.tblConsultationHours, a => a.consultationID, 
        ch => ch.consultationID, (a, ch) =>
            new StudentViewAppointment()
                {
                    AppointmentId = a.aptmtID,
                    Apremark = a.apremark,
                    APstatus = a.apstatus,
                    APsubject = a.apsubject,
                    ConsultationId = a.consultationID,
                    Day = ch.cday,
                    StartTime = (DateTime)ch.cstartTime,
                    EndTime = (DateTime)ch.cendTime,
                    LectureId = ch.lecturerID,
                    StudentId = a.studentID
                });
    }

Domain Service Class. cs

public partial class StudentViewAppointment
{
    [Key]
    public int AppointmentId { get; set; }
    public string Apremark { get; set; }
    public string APsubject { get; set; }
    public string APstatus { get; set; }
    public int ConsultationId { get; set; }
    public string StudentId { get; set; }
    public string Venue { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
    public string LectureId { get; set; }
    public string Day { set; get; }
}

Domain Service Class Metadata.cs

dgSlot.ItemsSource = context.StudentViewAppointments;
context.Load(context.StudentViewAppointmentsQuery("TP123123"));

Datagrid.xaml.cs

1myb
  • 3,536
  • 12
  • 53
  • 73

1 Answers1

3
return (from a in ObjectContext.tblaptmts
        join ch in ObjectContext.tblConsultationHours 
             on  a.consultationID equals ch.consultationID
        where  a.studentID == StuId
        select new StudentViewAppointment() 
                  {                       
                       AppointmentId = a.aptmtID,
                       Apremark = a.apremark,
                       -----
                       -----
                  });
  • Thx. finally done it. i found some error on my code and i changed to your return code =D – 1myb Nov 15 '11 at 11:35