Page 1 of 1

OrderByDescending followed by FirstOrDefault - does not work

Posted: Fri 03 Apr 2009 20:31
by pokaragat
Here's the query:

var lastSuccessLoginDate = scopeManager.LOGIN_ATTEMPTS.Where(c => c.LOGIN_STATUS == 'SUCCESS').OrderByDescending(c => c.LOGIN_DATE_TIME).FirstOrDefault();

Here's DBMonitor sql trace:

SELECT
"Project1".C1 AS C1,
........(omitted for clarity)
FROM ( SELECT
.......(omitted for clarity)
1 AS C1
FROM VCL.LOGIN_ATTEMPTS "Extent1"
WHERE ("Extent1".LOGIN_STATUS = &p__linq__305)
) "Project1"
WHERE ROWNUM <= (1)
ORDER BY "Project1".LOGIN_DATE_TIME DESC



Note:
The ROWNUM <= (1) comes before ORDEY BY

I would expect it to be implemented as:

SELECT
"Project1".C1 AS C1,
........(omitted for clarity)
FROM ( SELECT
.......(omitted for clarity)
1 AS C1
FROM VCL.LOGIN_ATTEMPTS "Extent1"
WHERE ("Extent1".LOGIN_STATUS = &p__linq__305)
ORDER BY "Project1".LOGIN_DATE_TIME DESC
) "Project1"
WHERE ROWNUM <= (1)

::the Order by is in the subquery.

Posted: Mon 06 Apr 2009 11:19
by AndreyR
This problem is fixed in dotConnect for Oracle 5.20.24 Beta.