Wrong SQL generated when using OrderBy and FirstOrDefault
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4177
Printed Date: 02-Apr-2025 at 5:10pm
Topic: Wrong SQL generated when using OrderBy and FirstOrDefault
Posted By: kdev
Subject: Wrong SQL generated when using OrderBy and FirstOrDefault
Date 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 ?
|
Replies:
Posted By: kimj
Date Posted: 17-Jun-2013 at 1:59pm
This appears to be an EF bug. See http://entityframework.codeplex.com/workitem/196 - http://entityframework.codeplex.com/workitem/196 .
|
Posted By: kdev
Date Posted: 18-Jun-2013 at 12:31am
|