Guest User

Untitled

a guest
May 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. есть запрос на Entity Framework который вызывает таблицы из БД по Id другой таблицы
  2.  
  3. var result = this.Context.LiveEnquiryServices
  4. .Include("LiveService")
  5. .Include("LiveEnquirySection")
  6. .Include("LiveEnquiryDocuments")
  7. .FirstOrDefault(x => x.LiveEnquirySectionId == liveEnquirySectionId && x.LiveServiceId == serviceId);
  8. return result;
  9.  
  10. public List<LiveEnquiryService> GetLiveEnquiryServices(Enquiry enquiry)
  11. {
  12. List<LiveEnquiryService> liveEnquiryService = new List<LiveEnquiryService>();
  13.  
  14. var query = $"SELECT LiveService.*, LiveEnquirySection.*, LiveEnquiryDocuments.* FROM LiveEnquiryServices WHERE LiveEnquirySectionId = '{enquiry.Id}';";
  15.  
  16. using (IDbConnection db = new SqlConnection(_connectionString))
  17. {
  18. liveEnquiryService = db.Query<LiveEnquiryService, LiveService, LiveEnquirySection, List<LiveEnquiryServiceDocument>, LiveEnquiryService>(query, (les, ls, lesn, lesd) =>
  19. {
  20. les.LiveService = ls;
  21. les.LiveServiceId = ls.Id;
  22. les.LiveEnquirySection = lesn;
  23. les.LiveEnquirySectionId = lesn.Id;
  24. les.LiveEnquiryDocuments = lesd;
  25. //les.LiveEnquiryDocuments = lesd;
  26. return les;
  27. }, splitOn: "Id").ToList();
  28.  
  29. }
  30. return liveEnquiryService.ToList();
  31. }
Add Comment
Please, Sign In to add comment