LINQ查询需要更多时间来执行

时间:2018-04-26 17:31:40

标签: c# asp.net-mvc performance linq linq-to-sql

这是我的LINQ查询,这需要很长时间才能执行 任何人都可以建议我如何加快速度 此查询需要大约1.35分钟才能加载。

从我在模型中添加的列表

var jobList = option.Equals("search")
        ? _jobService.SearchJobs(_dataModel.SearchFilter, _dataModel.CurrentPage - 1, _dataModel.EntriesPerPage,
            _dataModel.KeyWords, _dataModel.Location)
        : _jobService.BrowsJobs(_dataModel.BrowseFilterIds, _dataModel.CurrentPage - 1,
            _dataModel.EntriesPerPage);
    _dataModel.DbJobs = jobList;
    _dataModel.Jobs = jobList.Select(job => new JobsViewModel
    {
        JobId = job.JobId,
        JobTitle = job.JobTitle,
        SeoFriendlyJobTitle = job.JobTitle.ToSeoFriendly(),
        Created = job.Created,
        CreatedBy = job.CreatedBy,
        LocationName =
            job.LocationId != null
                ? _locationService.GetById((int)job.LocationId).LocationName
                : string.Empty,
        JobTypeName = _jobTypeService.GetById(job.JobTypeId).JobTypeName,
        RecruiterName =
            job.RecruiterId != new Guid()
                ? _recruiterService.GetById(job.RecruiterId).RecruiterName
                : string.Empty,
        SeoFriendlyRecruiterName =
            job.RecruiterId != new Guid()
                ? _recruiterService.GetById(job.RecruiterId).RecruiterName.ToSeoFriendly()
                : string.Empty,
        RecruiterId = job.RecruiterId,
        StartDate = job.StartDate,
        LocationDescription = job.LocationDescription,
        SalaryDescription = job.SalaryDescription,
        JobSummary = job.JobSummary,
        JobSummaryShort = job.JobSummaryShort,
        LogoPath = job.Logo.IsNullOrWhiteSpace() ? job.LogoOverride : job.Logo,
        PremiumJob = job.Advertising.Count > 0 && job.Advertising.ElementAt(0).PremiumListing,
        DaysRemaining = new Helpers().BuildDaysRemainingString(job.EndDate)
    }).ToList();

1 个答案:

答案 0 :(得分:0)

您的查询中是否包含服务调用?如果是这样,那很可能是造成缓慢的因素。