You need to add a using System.Linq;
(documentation) statement directive in the file where it isn’t working. All of the extension methods for IEnumerable/IQueryable are defined in the Enumerable and Queryable classes, respectively.
In order to use extension methods, the class defining the method must be in scope. My guess is that your second code snippet comes from another file where you do have the using statement.