Linq OrderByDescending and First problem
Posted: Mon 27 Apr 2009 04:04
Hello,
I'm not sure if this is a bug or if it's not possible.
I'm trying to get the first result of the rows return when I order the table by entryDate desc and where product id = some product id.
After playing around I found that this works
And this does not (which I realise now the first is a better way to do it)
When I load DbMonitor I can see that in the latter the order by is being left out.
Should these both not return the same result?
Thanks
Pleb.
I'm not sure if this is a bug or if it's not possible.
Code: Select all
CREATE TABLE `RealGamesFeedData`.`ProductHistoryLogs` (
`ProductHistoryLogId` char(36) NOT NULL,
`ProductId` char(36) NOT NULL,
`Action` enum('Updated','Created','Deleted') NOT NULL,
`Entry` datetime NOT NULL,
PRIMARY KEY (`ProductHistoryLogId`),
KEY `IN_ProductHistoryLogs_Entry` (`Entry`),
KEY `IN_ProductHistoryLogs_Action` (`Action`),
KEY `FK_ProductHistoryLogs_Product` (`ProductId`),
CONSTRAINT `FK_ProductHistoryLogs_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;After playing around I found that this works
Code: Select all
context.ProductHistoryLogSet.Where(p => p.Products.ProductId == "d27248b8-604a-bd93-0ed6-81c3033da219").OrderByDescending(log => log.Entry).First()Code: Select all
context.ProductHistoryLogSet.OrderByDescending(log => log.Entry).First(p => p.Products.ProductId == "d27248b8-604a-bd93-0ed6-81c3033da219")Should these both not return the same result?
Thanks
Pleb.