EF 4.1 - 代码优先 - 查询不再有效

时间:2011-12-02 04:33:42

标签: mysql entity-framework-4.1 ef-code-first

我先从使用edmx文件转到代码。以下查询不再有效(它基本上是限制为1的组):

(from sc in dbContext.student_courses
                                              where
                                                       sc.student_id == student.id 
                                                    && sc.course_id == course.id 
                                                    && sc.complete_flag == 1
                                              group sc by new
                                                        {
                                                          sc.complete_flag,
                                                          sc.direct_to_test_flag,
                                                          sc.dept_purchase_flag,
                                                          sc.issue_ce_flag,
                                                          sc.unlimited_purchase_flag,
                                                          sc.survey_taken
                                                        }
                                                  into scgroup
                                                  select new StudentCourseDetails
                                                                       {
                                                                           completeVideo = scgroup.Max(x => x.complete_flag),
                                                                           directToTest = scgroup.Max(x => x.direct_to_test_flag),
                                                                           isDepartmentPurchase = scgroup.Max(x => x.dept_purchase_flag),
                                                                           issueCE = scgroup.Max(x => x.issue_ce_flag),
                                                                           isUnlimitedPurchase = scgroup.Max(x => x.unlimited_purchase_flag),
                                                                           surveyTaken = scgroup.Max(x => x.survey_taken)
                                                                       }).FirstOrDefault();

生成的sql:

SELECT `Limit1`.`complete_flag`,
   `Limit1`.`C1`,
   `Limit1`.`C2`,
   `Limit1`.`C3`,
   `Limit1`.`C4`,
   `Limit1`.`C5`,
   `Limit1`.`C6`
FROM   (SELECT `GroupBy1`.`A1` AS `C1`,
           `GroupBy1`.`A2` AS `C2`,
           `GroupBy1`.`A3` AS `C3`,
           `GroupBy1`.`A4` AS `C4`,
           `GroupBy1`.`A5` AS `C5`,
           `GroupBy1`.`A6` AS `C6`,
           `GroupBy1`.`K1` AS `complete_flag`
    FROM   (SELECT Max(`complete_flag`)           AS `A1`,
                   Max(`direct_to_test_flag`)     AS `A2`,
                   Max(`dept_purchase_flag`)      AS `A3`,
                   Max(`issue_ce_flag`)           AS `A4`,
                   Max(`unlimited_purchase_flag`) AS `A5`,
                   Max(`survey_taken`)            AS `A6`
            FROM   `student_courses` AS `Extent1`
            WHERE  ((`Extent1`.`student_id` = 3885 /* @p__linq__0 */)
                    AND (`Extent1`.`course_id` = 606 /* @p__linq__1 */))
                   AND (1 = `Extent1`.`complete_flag`)
            GROUP  BY `Extent1`.`complete_flag`,
                      `Extent1`.`dept_purchase_flag`,
                      `Extent1`.`direct_to_test_flag`,
                      `Extent1`.`issue_ce_flag`,
                      `Extent1`.`survey_taken`,
                      `Extent1`.`unlimited_purchase_flag`) AS `GroupBy1`
    LIMIT  1) AS `Limit1`

问题在于,当它添加限制1时,它还会添加一个额外的列:
GroupBy1K1 AS complete_flag - 不存在。

有什么想法吗?

0 个答案:

没有答案