I'm developing a method for an API that consists of the following: fetch all evaluations from a given client and, if specified, limit 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 of here was this: When doing var query = *consulta*
I would only be creating the query
, which will only be executed later (with ToList()
or, in this case, when returning the data).
Is that right, or does the query run in that first instance of the example?