Quantcast
Channel: patterns & practices: Project Silk
Viewing all articles
Browse latest Browse all 93

New Post: Performance issue

$
0
0
Hi,

The following note, took from Chapter 11 - Server-Side Implementation - Implementing the Repository Pattern explains the design decisions took by the team regarding this topic:

The IReminderRepository interface returns collections as IEnumerable<T>, rather than IList<T> or ICollection<T>. This was an intentional design choice to prevent the direct addition of entities to the collections. To create a new reminder, the developer must use the Create method.
In Mileage Stats, the implementation of the IReminderRepository calls ToList before returning the IEnumerable<T>. This is to ensure that the query is executed inside the repository. If ToList was not called, then the repository would return an IQueryable<T> and the database would not be accessed until something iterated over the IQueryable<T> object. The problem with returning an IQueryable<T> is that a developer consuming the API is likely to assume that the query has already executed and that you are working with the results. If you iterate over the query more than once, it will result in multiple calls to the database.
If you specifically want your repository to return queries instead of results, use the IQueryable<T> on the interface in order to make your intention explicit.

I hope this helps in understanding the architecture of the project and the design decisions behind the Mileage Stats implementation.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Viewing all articles
Browse latest Browse all 93

Trending Articles