Current project, broke head over this problem:
Client Repository:
public class ClientRepository
{
// Members
private masterDataContext _db;
Wow. You do a lot of looping there. Each Where
inside the loop ends up looping an array to find an item, every iteration in the loop.
Make dictionaries of the clients, so that you can look them up qickly. That should give you a dramatic increase in speed:
public ActionResult Index()
{
private ClientRepository _cr = new ClientRepository();
var _retailclients = _cr.GetRetailClientNames().ToDictionary(c => c.id);
var _corporateclients = _cr.GetCorporateClientNames().ToDictionary(c => c.id);
var _visits = _db.GetAllServiceVisits();
var _temp = _visits.Select(o => new ServiceVisitViewModel
{
service_visit = o,
client = (o.client_type ? _corporateclients[o.client_id].name : _retailclients[o.client_id].name)
}).ToArray();
return View(_temp);
}