r
is the composed query - an IQueryable<Product>
or similar; note the query has not yet executed - it is just a pending query. var
means "compiler, figure out the type of r from the expression on the right". You could have stated it explicitly in this case, but not all. But it wouldn't add any value, so var
is fine.
p
is a convenience marker for each product; the query is "for each product (p), restricting to those with unit price greater than 15 (where p > 15
), select that product (select p
) as a result.
Ultimately this compiles as:
IQueryable<Product> r =
db.Products.Where(p => p.UnitPrice > 15);
(in this case, a final .Select(p => p)
is omitted by the compiler, but with a non-trivial projection, or a trivial query, the .Select(...)
is retained)