tôi có 5 bảng mà từ đó tôi muốn lấy một số thông tin bằng cách sử dụng linq.i đang sử dụng truy vấn sau để đọc dữ liệu từ dữ liệu.Nhiều tham gia với groupby trong linq
var query = (from GRD in _tblStudents.GetQueryable()
join apt in _tblApplicants.GetQueryable()
on GRD.ApplicantID equals apt.ApplicantID
join cls in _tblClasses.GetQueryable()
on GRD.CityID equals cls.ClassID
join prg in _tblPrograms.GetQueryable()
on cls.ProgramID equals prg.ProgramID
join city in _tblCities.GetQueryable()
on GRD.CityID equals city.CityID
where GRD.AcademicYearID == yearId && cls.ProgramID == programId
group apt by new{apt.Gender} into grouped
select new CityWiseStudentModel
{
CityName=city.CityName,
//'city' does not exist in the current context
Gender = grouped.Count(),
programName=prg.Program,
//'prg' does not exist in the current context
}
);
Làm thế nào tôi có thể có được tên thành phố từ thành phố bảng và tên chương trình từ PRG bảng
Thử 'join into' thay vì chỉ' join' để truyền bá các mục được nhóm trong toàn bộ truy vấn. Lưu ý rằng bạn sẽ cần phải viết lại truy vấn vì bạn không thể có 'join' trực tiếp theo sau' join into' (cần một 'select' trung gian). – Kryptos