Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. var query = from p in db.Payments
  2. where p.Status == false
  3. && DateTime.Compare(DateTime.Now, p.NextPaymentDate.Value) == 1
  4. group p by p.CompanyID into op
  5. select op.OrderByDescending(nd => nd.NextPaymentDate.Value).FirstOrDefault();
  6.  
  7. var query = from p in db.Payments
  8. where p.Status == false
  9. group p by p.CompanyID into op
  10. select new {
  11. CompanyID = op.Key,
  12. NextPaymentDate = op.Max(x => x.NextPaymentDate),
  13. Status = false
  14. };
  15.  
  16. I need to do the same. But in Datacontext. And i need to join three tables.
  17.  
  18. var year = dContext.Reviews.Max(a => a.Year);
  19. var awardsList = dContext.Awards
  20. .Join(dContext.Reviews, a => a.ReviewId, r => r.Id, (a, r) => new { a, r })
  21. .Join(dContext.CompanyInfoes, cr => cr.r.CompanyInfoId, ci => ci.Id, (cr, ci) => new { cr.a, cr.r, ci })
  22. .Where(pcu => !(pcu.r.IsDeleted.HasValue && pcu.r.IsDeleted.Value)).Select(p => new AwardsAndComplianceModel()
  23. {
  24. YearOfReview = year,
  25. CompanyName = p.ci.Name,
  26. ReportStatus = p.r.Status,
  27. Id = p.ci.Id,
  28. CompanyProfileId = p.ci.Id,
  29. AwardsComplianceTitle = p.a.Title,
  30. AwardedBy = p.a.AwardedBy,
  31. Date = p.a.Date,
  32. Country = p.a.Country,
  33. Remarks = p.a.Remarks`enter code here`
  34. }).ToList();
  35.  
  36. After this i have to check not null condition for each record also
Add Comment
Please, Sign In to add comment