Drawback of Last() method in LINQ to SQL

Note that Last() method can be extremely slow on big data set. For example Listing 7.1 takes about 10 seconds. The reason is the Last() method can't be translated into SQL query and the whole table was loaded into the memory.
var result =
    (from s in emp.Salaries
        select s.Salary).Last();

Listing 7.1

If you have unique id in the table the Last() can be replaced with orderby and First() method, that will be much more efficient
var result =
    (from s in emp.Salaries
        orderby s.EmPNo descending
        select s.Salary).First();

Listing 7.2

No comments:

HOWTO: Repair Logitech M325 Mouse

FixIt says that you will find single screw under CE label. It isn't always true.