gpt4 book ai didi

c# - 返回连接表

转载 作者:行者123 更新时间:2023-11-30 22:33:45 29 4
gpt4 key购买 nike

我已经为我的域上下文输入了这个 linq 查询,但为什么它无法检索 tblaptmt 中与学生 ID 匹配的两个表的数据?

    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
});
}

域服务类。 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; }
}

域服务类元数据.cs

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

Datagrid.xaml.cs

最佳答案

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,
-----
-----
});

关于c# - 返回连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8135014/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com