I have a query below. although can anyone point out what “from p” means? and also “var r”?
DataClasses1DataContext db = new DataClasses1DataContext();
var r = from p in db.Products
where p.UnitPrice > 15 // If unit price is greater than 15...
select p; // select entries
ris the composed query – anIQueryable<Product>or similar; note the query has not yet executed – it is just a pending query.varmeans “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, sovaris fine.pis 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:
(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)