生成任何持续时间的日期,并将其与学生考试/标记列表的LINQ查询集成

时间:2013-04-16 22:06:42

标签: linq

I have a Exam date table and marks of students and while generating report the user can select any date could be 20 years from now. The report has to show the date and Day but blank marks and course names. I am using LINQ query as below:

    select * from (
      select w.exam_date,  w.score, w.labscore,
        w.high_num, w.low_num
      from Exam w
      left outer join student ca on w.stuid= ca.stuid
      where w.exam_dte between '01-sep-2012' and '10-sep-2012'
    ) a 
    order by a.exam_dte

我正在将Exam表作为参考来获取我的日期和日期部分,但是在用户选择任何未来日期的情况下我如何在LINQ中实现。

    from a in (
        (from w in db.Exam 
        join ca in student on new { stuid = w.stuid } equals new { stuid = ca.stuid } into ca_join
        from ca in ca_join.DefaultIfEmpty()
        where
          w.exam_date >= "01-sep-2012" && w.exam_date <= "10-sep-2012"
        select new {
          exam_date= (System.DateTime?)w.exam_date,
          score = (System.Int32?)w.score,
          labscore = (System.Int32?)w.labscore,
          w.high_num, 
          w.low_num
        }))
    orderby
      a.exam_date
    select new {
      a.exam_date,
      w.score, 
      w.labscore,
      w.high_num, 
      w.low_num
    }

以上是linq查询,其中我使用了Exam表中的日期并生成以下报告

Date 09/01/2012      09/02/2012    09/03/2012
Day     Wed              Thu           Fri
Score   100              99           80

我的工作报告中包含考试表中的日期。如果日期是考试表中没有的未来日期,则不起作用。请帮助生成一个生成日期的linq查询,而不是参考Exam表。

0 个答案:

没有答案