Current project, broke head over this problem:
Client Repository:
public class ClientRepository
{
// Members
private masterDataContext _db;
The Select statement makes a huge difference here - because it's changing what's being done at the database. (I'm assuming _db.GetAllServiceVisits() returns an IQueryable.)
You're fetching all the retail and corporate clients into memory already because you're using ToArray. Your Select call will (I suspect) then be sending all that data back to the database so that the Select and Where can be performed there. I suspect if you look in SQL profiler, it'll be a pretty odd query.
If you force everything to be done client-side, it should be bassically the same as your latter approach. You can do that easily, with:
var _visits = _db.GetAllServiceVisits().ToList();
... however, that means you're pulling all of three tables from your database each time you hit this page. That doesn't sound like a good plan to me.
However, it would be better if you could do everything in the database without fetching all the retail and corportate clients into memory first.
That may be as simple as changing your repository methods to return IQueryable instead of IEnumerable, and removing the calls to AsEnumerable.