You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses the Entity Framework.
The application has an entity model that contains a SalesOrderHeader entity. The entity includes an OrderDate property of type DateTime.
You need to retrieve the 10 oldest SalesOrderHeaders according to the OrderDate property.
Which code segment should you use?
A.
var model = new AdventureWorksEntities();
var sales = model.SalesOrderHeaders.Take(10).OrderByDescending(soh => soh.OrderDate);
B.
var model = new AdventureWorksEntities();
var sales = model.SalesOrderHeaders.OrderByDescending(soh => soh.OrderDate).Take(10);
C.
var model = new AdventureWorksEntities();
var sales = model.SalesOrderHeaders.OrderBy(soh => soh.OrderDate).Take(10);
D.
var model = new AdventureWorksEntities();
var sales = model.SalesOrderHeaders.Take(10).OrderBy(soh => soh.OrderDate);
Explanation:
OrderBy() Sorts the elements of a sequence in ascending order according to a key.
OrderByDescending() Sorts the elements of a sequence in descending order according to a key.Enumerable.OrderBy<TSource, TKey> Method (IEnumerable<TSource>, Func<TSource, TKey>)
(http://msdn.microsoft.com/en-us/library/bb534966.aspx)
Should it be OrderByDescending(), because “You need to retrieve the 10 oldest SalesOrderHeaders according to the OrderDate property” ?
Yes the answer should be (B) since we need the oldest.
Fish, the perfect send off for LKY is for all those psreecuted, detained without justification to sing “My Way” while pissing on his grave.For what is a man, what has he got?If not himself, then he has naughtTo say the things he truly feels,And not the words of one who kneelsThe record shows, I took the blows,And did it My Way !