code_junkie

Linq To Sql return from function as IQueryable<T>

Nov 13th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public IQueryable getTicketInformation(int ticketID)
  2. {
  3. var ticketDetails = from tickets in _context.tickets
  4. join file in _context.file_objects on tickets.ticket_id equals file.source_id
  5. where tickets.ticket_id == ticketID
  6. select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename };
  7.  
  8. return ticketDetails.AsQueryable();
  9. }
  10.  
  11. public IQueryable<myObject> getTicketInformation(int ticketID)
  12. {
  13. var ticketDetails = from tickets in _context.tickets
  14. join file in _context.file_objects on tickets.ticket_id equals file.source_id
  15. where tickets.ticket_id == ticketID
  16. select new { tickets.ticket_id, tickets.title, tickets.care_of_email, file.filename };
  17.  
  18. return ticketDetails.AsQueryable()<myObject>;
  19. }
  20.  
  21. public myObject getTicketInformation(int ticketID)
  22. {
  23.  
  24. ....linq statement....
  25. myObject o = null;
  26.  
  27. foreach (obj in linqstatemt)
  28. {
  29. o = new myObject();
  30. o.ticket_id = obj.ticket_id
  31. .......
  32. }
  33. return o;
  34. }
  35.  
  36. select new MyObject { TicketId = tickets.ticket_id,
  37. Title = tickets.title, ...};
  38.  
  39. select new MyObject(tickets.ticket_id, tickets.title);
  40.  
  41. return ticketDetails.AsQueryable()<myObject>;
  42.  
  43. return ticketDetails.AsQueryable<myObject>();
  44.  
  45. public IQueryable<myObject> getTicketInformation(int ticketID)
  46. {
  47.  
  48. return from tickets in _context.tickets
  49. join file in _context.file_objects on tickets.ticket_id equals file.source_id
  50. where tickets.ticket_id == ticketID
  51. select new myObject() {
  52. ticket_id = tickets.ticket_id,
  53. title = tickets.title,
  54. care_of_email = tickets.care_of_email,
  55. filename = file.filename
  56. };
  57.  
  58. }
Add Comment
Please, Sign In to add comment