Don't try to solve potential performance issues too early in the process (but don't ignore them, either).
As always, how you actually execute the query depends on the nature of the data, and how it will be used. If you've got a batch process running through tens/thousands of records, you'd want to let SQL Server take care of it.
However, if you only need to execute the query once or twice, with fewer records, you can get away with an in-memory loop.
The missing piece to you solution is this: Use a Query Specification to wrap your query, and make your Author
object use this new Query Specification.
Initially, just make it a simple loop. When you discover that it's too slow, replace the loop with a call to the database (via a FindAwardWinningBookCount
method on your AuthorRepository
).
The important part is this: Your Author
object is no longer responsible for handling the query - it uses the Query Specification instead. Changing the Query Specification's implementation should not affect the behaviour of your Author
.
See pages 229 to 234 in Evan's book for more detail.