public class StudentDetails
{
public string Type{get; set;}
public DateTime StartDate { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public DateTime EndDate { get; set; }
public string Course { get; set; }
}
I have created List using above code and is used it in a following code :
[WebMethod]
public StudentDetails[] GetTodayReport(int StudentID, DateTime startdate)
{
DateTime tartdate = DateTime.UtcNow.AddDays(-3);
try
{
context = new TMSEntities();
List<string> sdetails = new List<string>();
DataTable NewTable = new DataTable();
NewTable.Columns.AddRange(new DataColumn[6] { new DataColumn("Type", typeof(string)), new DataColumn("StartDate", typeof(string)), new DataColumn("Name", typeof(string)), new DataColumn("Status", typeof(string)), new DataColumn("EndDate", typeof(string)), new DataColumn("Course", typeof(string)) });
var query = (from E in context.tbl_ExamCreation
join EA in context.tbl_ExamAttendence on E.Exam_ID equals EA.Exam_ID
join C in context.tbl_Course on E.Course_ID equals C.CourseID
where EA.StudentID == StudentID && SqlFunctions.DateDiff("DAY", E.DateOfExam, tartdate) == 0 && E.Status == "A"
select new { Type = "Exam", StartDate = E.DateOfExam, Name = E.ExamName, Status = EA.status, EndDate = E.ExamEndDatetime, Course = C.Name })
.Union
(from LS in context.tbl_LectureScheduling
join LA in context.tbl_LectureAttendence on LS.LectureScheduleID equals LA.LectureScheduleID
join L in context.tbl_Lectures on LS.LectureID equals L.LectureID
join CR in context.tbl_Course on L.CourseID equals CR.CourseID
where LA.StudentID == StudentID && SqlFunctions.DateDiff("DAY", LS.StartDateTime, startdate) == 0 && LS.Status == "A"
select new { Type = "Lecture", StartDate = LS.StartDateTime, Name = L.LectureName, Status = LA.status, EndDate = LS.EndDateTime, Course = CR.Name }
);
return query.Select(x=>new StudentDetails() { Type = x.Type, StartDate = x.StartDate, Name = x.Name, Status = x.Status , EndDate = x.EndDate, Course = x.Course }).ToArray();
}
catch (Exception ex)
{
return null;
}
}
}
But an error occured at the X.StartDate and x.EndDate as :
Error 23 Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
Please let me know if solution exists