Does it matter where AsNoTracking in Entity Framework is called

As Cdaragorn said in the comments.

You cannot call AsNoTracking after ToList because you no longer have an IQueryable to call it on. It will give a compile time error.

In the case you could do what OP is asking I am going to explain how the query would work because could help others to understand these matters:

With

var matchingCustomers = context.Customers.Where(n => n.city == "Milan").Skip(50).Take(100).OrderBy(n => n.Name).ToList().AsNoTracking();

you are trying to apply NoTracking to a data structure already in memory once EF has executed, and traked, the query.

When you use this fluent API; you are defining a query without executing it until you, of course, execute the query. ToList() will execute the query an bring the data to memory to transform it into a List<T> data structure.

Let's split the command to understand this:

  • context.Customers --> Select [*] from Customers
  • Where(n => n.city == "Milan") --> Select [*] from Customers where city == 'Milan'
  • Skip(50).Take(100) --> Select [*] from Customers where city == 'Milan' OFFSET 50 ROWS FETCH NEXT 100 ROWS ONLY
  • OrderBy name --> Select [*] from Customers where city == 'Milan' OFFSET 50 ROWS FETCH NEXT 100 ROWS ONLY ORDER BY name
  • ToList() --> Execute the query and bring the data into memory with Tracking by default!
  • AsNoTraking() --> Does nothing because EF already executed the query and tracked the data.

No it doesn't matter: (source)

A new query with NoTracking applied, or the source query if NoTracking is not supported.

So you either do it in the beginning and you expand the "new" query with the method chain, or you do it in the end and then get the "new" query. As long as you call it before the query is executed you're fine.