Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
;WITH MyCte(EType,EventDate,EName,EStatus) AS
(
SELECT     'Exam' AS Expr1, E.DateOfExam, E.ExamName,tbl_ExamAttendence.status
FROM         tbl_ExamCreation AS E INNER JOIN
                      tbl_ExamAttendence ON E.Exam_ID = tbl_ExamAttendence.Exam_ID
WHERE     (tbl_ExamAttendence.StudentID = 1044)
UNION ALL
SELECT     'Lecture' AS Expr1, LS.StartDateTime, tbl_Lectures.LectureName,tbl_LectureAttendence.status
FROM         tbl_LectureScheduling AS LS INNER JOIN
                      tbl_LectureAttendence ON LS.LectureScheduleID = tbl_LectureAttendence.LectureScheduleID INNER JOIN
                      tbl_Lectures ON LS.LectureID = tbl_Lectures.LectureID
WHERE     (tbl_LectureAttendence.StudentID = 1044)
)

SELECT TOP 5 EType,EventDate,EName,EStatus FROM MyCte ORDER BY EventDate DESC
Posted

C#
var datas=(from d in entityObj.GetDataFunction into somename select new{somename.ID,Somename.Name....}.Take(5);


C#
public class Dto
{
public int EType{get;set;}
public DateTime EventDate{get;set;}
public string EName{get;set;}
public string EStatus{get;set;
}

var myCte1=(from m in entityObj.tbl_ExamCreation join tb in tbl_ExamAttendence ON E.Exam_ID = tb.Exam_ID select new{ EType="Exam",EventDate=m .DateOfExam, EName=m.ExamName,EStatus=tb.status}).Select(x=>new Dto{EType=x.EType,EventDate=x.EventDate,EName=x.EName,EStatus=x.EStatus});


write same for part after Union all

and you can apply union all for these two data and take Top 5 using

C#
var finalResult= myCte1.Concat(myCte2).Take(5);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900