Am using the datasource which is from the MVC controller method GetRepairIssues in the client side to bind the options to the dropdownlist. The result comes as expected. I have to do it even better and optimistic. public JsonResult GetRepairIssues(){    JsonResult result = null;    try    {        var repairIssues = from repairIssue in RelationshipManagementService.GetRepairIssues<RepairIssue>().ToList()                           select new RepairIssueViewModel                           {                               Id = repairIssue.Id,                               Description = repairIssue.Description,                               IsActive = repairIssue.IsActive,                               CreatedBy = repairIssue.CreationTransaction.ExecutedBy.Name,                               CreatedDate = DateTimeConverter.FromUTCWithTimeZoneAbbrevation(repairIssue.CreationTransaction.ExecutionTime, AuthenticatedUser.TimeZoneInfo),                               ModifiedBy = repairIssue.LastEditTransaction != null ? repairIssue.LastEditTransaction.ExecutedBy.Name : string.Empty,                               ModifiedDate = repairIssue.LastEditTransaction != null ? DateTimeConverter.FromUTCWithTimeZoneAbbrevation(repairIssue.LastEditTransaction.ExecutionTime, AuthenticatedUser.TimeZoneInfo) : string.Empty,                               RepairIssueAssociationValues = (from repairGroup in repairIssue.RepairIssueRepairGroupAssociations.Where(a => a.IsActive).ToList()                                                               select new RepairIssueAssociationViewModel                                                               {                                                                   Id = repairGroup.RepairGroupId,                                                                   RepairGroup = repairGroup.RepairGroup.Description                                                               }).ToList(),                           };        result = Json(repairIssues.OrderByDescending(r => r.Id).ToList(), JsonRequestBehavior.AllowGet);    }    catch (Exception ex)    {        result = Json(new { data = string.Empty, success = false, message = ex.Message }, JsonRequestBehavior.AllowGet);    }    return result;}Appreciate your help..
How to optimize the below code in order to reduce the space and time to execute?
c#;mvc;controller
Without the actual model and some numbers (how long does it take to execute/ how much 'space' it takes?) might be hard to optimize, but what I can tell is that you call .ToList() quite a lot in such short method. When you do call it you basically iterate over a source (is it DB source? in memory source? other?) and grab it to the memory of your process.Try reducing the number of calls .ToList() - it will improve your performance.Take a look at this fragment:(from repairGroup in repairIssue.RepairIssueRepairGroupAssociations.Where(a => a.IsActive).ToList()   select new RepairIssueAssociationViewModel {        Id = repairGroup.RepairGroupId,        RepairGroup = repairGroup.RepairGroup.Description   }).ToList()You are calling .ToList() on a source basically retrieving the whole collection with all the properties and only later you are taking just the two fields. If you want to reduce time and space - try taking only what's needed from the underlying source, but also it greatly depends on the typo of source you are using underneath.Consider dropping the LINQ at all. LINQ is great and compact but it has it's 'dark side' in term of hidden allocations.Also think abount some old-hasioned ways like 'paging'? For the dropdown that might not be the best way - but maybe it is. If for most cases only the top 20 repair issues are accessed then here's your optimization - and for few cases user would need to load more items to the list - that might be ok.