New Posts New Posts RSS Feed: Wrong SQL generated when using OrderBy and FirstOrDefault
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Wrong SQL generated when using OrderBy and FirstOrDefault

 Post Reply Post Reply
Author
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Topic: Wrong SQL generated when using OrderBy and FirstOrDefault
    Posted: 14-Jun-2013 at 2:57am
Hi,


I have an issue with the generated SQL of a query using Orderby and FirstOrDefault.

Let's say we have those 2 queries :

var qry = from myentity in myquery.Where(d => d.Id == 348802)
           select myentity.mypropertynavigation.OrderByDescending(m => m.Debut).Where(m => m.Debut <= DateTime.Today).FirstOrDefault();

=> It will correctly apply the ORDER BY and select the TOP(1)

var qry = from myentity in myquery.Where(d => d.Id == 348802)
           select myentity.mypropertynavigation.OrderByDescending(m => m.Debut).FirstOrDefault(m => m.Debut <= DateTime.Today);

=> It will ONLY select the TOP(1), the SQL contains no ORDER BY at all.


Is this a DF bug ?

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2013 at 1:59pm
This appears to be an EF bug. See http://entityframework.codeplex.com/workitem/196.
Back to Top
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jun-2013 at 12:31am
Ok, thanks kimj
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down