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:

Asterisk AST_SORCERY function

 AST_SORCERY gets a field from a sorcery object. Sorcery is always created for PJSIP aors, endpoints and identifies in asterisk. It allows y...