code_junkie

How can I add an additional object to the results of a LINQ query?

Nov 12th, 2011
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public IEnumerable<ProdPriceDisplay> GetShopProductsPrices()
  2. {
  3.  
  4. //ProdPriceDisplay ProdPrice = new ProdPriceDisplay();
  5. var Products = from shop in db.SHOPs
  6. select new ProdPriceDisplay
  7. {
  8. ProdPrice = shop.S_NAME + " - £" + shop.S_PRICE
  9. };
  10.  
  11. // *** Want to add something like this:-
  12.  
  13. // Products.Add new ProdPriceDisplay { ProdPrice = "some additional text"; }
  14.  
  15. return Products;
  16. }
  17.  
  18. public IEnumerable<ProdPriceDisplay> GetShopProductsPrices()
  19. {
  20. var products = from shop in db.SHOPs
  21. select new ProdPriceDisplay
  22. {
  23. ProdPrice = shop.S_NAME + " - £" + shop.S_PRICE
  24. };
  25.  
  26. return products.AsEnumerable()
  27. .Concat(new [] { new ProdPriceDisplay
  28. { ProdPrice = "some additional text"; });
  29. }
  30.  
  31. var productsAsList = Products.ToList();
  32. productsAsList.Add(new ProdPriceDisplay { ProdPrice = "some additional text"; });
  33.  
  34. return productsAsList; // As your return type is IEnumarable, that won't be a problem;
Add Comment
Please, Sign In to add comment