linq表達式 多表關聯查詢,左連接查詢


多表關聯查詢
             from x in _wholesalerReplenishmentDetailRepository.GetAll()
                      join n in _wholesalerReplenishmentRepository.GetAll() on x.WholesalerReplenishmentId equals n.Id  //批發商補貨
                      join y in _store.GetAll() on x.StoreId equals y.Id //店鋪
                      join z in _wholesalerEmployeeRepository.GetAll() on x.EmployeeId equals z.Id into groupsz
                      from grpz in groupsz.DefaultIfEmpty() //業務員(可能為空)
                      join m in _wholesalerRepository.GetAll() on x.WholesalerId equals m.Id into groupsm
                      from grpm in groupsm.DefaultIfEmpty() //批發商(可能為空)
                      orderby x.CreationTime descending
                      select new WholesalerReplenishmentFullDto
                      {
                          Id = x.Id,
                          CompanyName = grpm.CompanyName,
                          EmployeeName = x.EmployeeId == null ? grpm.ContactPerson : grpz.EmployeeName,//可能批發商自己補貨,//可能批發商自己補貨,
                          StoreName = y.Name,
                          StoreBossName = y.BossName,
                          CreatTime = x.CreationTime,
                          CreationAddress = n.CreationAddress,
                          OpratorId = x.LastModifierUserId == null ? x.CreatorUserId : x.LastModifierUserId,
                          OpratorTime = x.LastModificationTime == null ? x.CreationTime : x.LastModificationTime,
                          ProductId = x.ProductId
                      };

let設置臨時條件

          from u in users
             let number = Int32.Parse(u.Username.Substring(u.Username.Length - 1))
             where u.ID < 9 && number % 2 == 0
             select u

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM