13
I am developing a method for an API that consists of the following: fetching all customer reviews and, if specified, limiting the amount of records that will be returned.
For example:
public IEnumerable<Avaliacao> GetAvaliacoes(int idCliente, [FromUri]uint limit = 0)
{
var query = contexto.Avaliacoes.Include(x => x.Notas)
.Where(a => a.IdCliente == idCliente)
.OrderByDescending(x => x.DataRegistro);
if (limit != 0)
return query.Take((int)limit);
return query;
}
What I thought here was this: to do var query = *consulta*
I’d just be creating to query
, which will only be implemented later (with ToList()
or, in this case, when returning the data).
Is that right or the query is executed at that first moment of the example?
Related (en): http://stackoverflow.com/q/2678405/4190610
– Jéf Bueno