code_junkie

C#: Is it possible to declare a local variable in an anonymous method?

Nov 13th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. IQueryable<Enquiry> linq = db.Enquiries;
  2.  
  3. if(...) linq = linq.Where(...);
  4.  
  5. if(...) linq = linq.Where(e =>
  6. (x <= (from p in db.Orders where p.EnquiryId == e.Id select p).Count() &&
  7. (from p in db.Orders where p.EnquiryId == e.Id select p).Count() <= y));
  8.  
  9. if(...) linq = linq.Where(...);
  10.  
  11. var result = (from e in linq select e);
  12.  
  13. x => { int y = x + 1; return x + y; }
  14.  
  15. delegate(int x) {
  16. int y = x + 1;
  17. return x + y;
  18. }
  19.  
  20. ... = linq.Where(e => {
  21. var count = (from p in db.Orders where p.EnquiryId == e.Id select p).Count();
  22. return x <= count && count <= y;
  23. });
  24.  
  25. ... = from e in linq
  26. let count = (from p in db.Orders where p.EnquiryId == e.Id select p).Count()
  27. where (x <= count) && (count <= y)
  28. select e;
  29.  
  30. where (x <= count) && /* <= */ (count <= y);
  31.  
  32. public static Boolean Between(this int value, int from, int to)
  33. {
  34. return from <= value && value <= to;
  35. }
  36.  
  37. (count => x <= count && count <= y)
  38. ((from p in db.Orders
  39. where p.EnquiryId == e.Id
  40. select p).Count())
Add Comment
Please, Sign In to add comment