首页 > 其他 > 详细

linq

时间:2020-06-24 14:36:34      阅读:64      评论:0      收藏:0      [点我收藏+]

 

查出来0条

        public async Task<PagedResultDto<ProFileListDto>> GetAll(ProFileListInput input)
        {
            var query = from a in _proFileRepository.GetAll()
                        join b in _filingAgreementRepository.GetAll() on a.Id equals b.ProFileId into list
                        from c in list.DefaultIfEmpty()
                        join d in _filesRepository.GetAll() on c.PdfFileUrlId equals d.Id
                        where (string.IsNullOrEmpty(input.Name) || a.Name == input.Name) &&
                              (!input.GraduationTime.HasValue || a.GraduationTime.Year == input.GraduationTime.Value) &&
                              (!input.Birthday.HasValue || a.Birthday.Value.Year == input.Birthday.Value.Year
                                                             && a.Birthday.Value.Month == input.Birthday.Value.Month) &&
                              (string.IsNullOrEmpty(input.IdCard) || a.IdCard == input.IdCard) &&
                              (!input.ProFileState.HasValue || a.ProFileState == input.ProFileState) &&
                              (!input.ProFileType.HasValue || a.ProFileType == input.ProFileType) &&
                              (string.IsNullOrEmpty(input.GraduatedSchool) || a.GraduatedSchool == input.GraduatedSchool)
                        select new { a, url=d==null?"":d.FliePath };



            var count = await query.CountAsync();
            var items = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();

            return new PagedResultDto<ProFileListDto>(
                count,
                items.Select(item =>
                {
                    var dto = ObjectMapper.Map<ProFileListDto>(item.a);
                    //if (item.c != null)
                    //{
                    //    dto.FilingAgreementFileUrl = ( _filesRepository.Get(item.c.PdfFileUrlId)).FliePath;
                    //}
                    dto.FilingAgreementFileUrl = item.url;
                    return dto;
                }).ToList());
        }

 

正常

     public async Task<PagedResultDto<ProFileListDto>> GetAll(ProFileListInput input)
        {
            var query = from a in _proFileRepository.GetAll()
                        join b in _filingAgreementRepository.GetAll() on a.Id equals b.ProFileId into list
                        from c in list.DefaultIfEmpty()
                        //join d in _filesRepository.GetAll() on c.PdfFileUrlId equals d.Id
                        where (string.IsNullOrEmpty(input.Name) || a.Name == input.Name) &&
                              (!input.GraduationTime.HasValue || a.GraduationTime.Year == input.GraduationTime.Value) &&
                              (!input.Birthday.HasValue || a.Birthday.Value.Year == input.Birthday.Value.Year
                                                             && a.Birthday.Value.Month == input.Birthday.Value.Month) &&
                              (string.IsNullOrEmpty(input.IdCard) || a.IdCard == input.IdCard) &&
                              (!input.ProFileState.HasValue || a.ProFileState == input.ProFileState) &&
                              (!input.ProFileType.HasValue || a.ProFileType == input.ProFileType) &&
                              (string.IsNullOrEmpty(input.GraduatedSchool) || a.GraduatedSchool == input.GraduatedSchool)
                        select new { a, c/*url=d==null?"":d.FliePath*/ };
            


            var count = await query.CountAsync();
            var items = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();

            return new PagedResultDto<ProFileListDto>(
                count,
                items.Select(item =>
                {
                    var dto = ObjectMapper.Map<ProFileListDto>(item.a);
                    if (item.c != null)
                    {
                        dto.FilingAgreementFileUrl = (_filesRepository.Get(item.c.PdfFileUrlId)).FliePath;
                    }
                    //dto.FilingAgreementFileUrl = item.url;
                    return dto;
                }).ToList());
        }

 

linq

原文:https://www.cnblogs.com/wangyinlon/p/13187313.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!