Skip to content

ListService

Jon Smith edited this page Jan 20, 2015 · 2 revisions

The ListService is used to return a list of items from the database. This is typically a set of properties that represent each row in a table and are often represented as a grid or table to the user.

The ListService has one command that returns an IQueryable<> list of the type T. Where T is either data class or DTO. If T is the data class then it simply returns that. If T is a DTO inherited from either EfGenericDto (sync) or EfGenericDtoAsync (async) then the data properties are copied over using a convention-based object-object mapping (see AutoMapper). This allows the data to be 'shaped'. See SimplePostDto for an example of this.

The ListService has a single command:

  • IQueryable<T> GetAll<T>()

The returned IQueryable<T> list can have further commands applied to it. This allows you to order, filter, page, include, select etc.

Note that the ListService is not sync or async, but returns IQueryable. Therefore you add a LINQ command on the end, e.g .ToList() or .ToListAsync(). You can see this by comparing the return statements in the Index action from the:

  • Sync version of the Posts Controller which uses .ToList().
  • Async version of the Posts Controller which uses .ToListAsync().