code_junkie

Using Linq, how can I pass a var back from a method?

Nov 10th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. var myData = from a in db.MyTable
  2. where a.MyValue == "A"
  3. select new
  4. {
  5. a.Key,
  6. a.MyValue
  7. };
  8.  
  9. public ??? GetSomeData()
  10. {
  11. // my Linq query
  12. }
  13.  
  14. var myData = from a in db.MyTable
  15. where a.MyValue == "A"
  16. select new MyType
  17. {
  18. Key = a.Key,
  19. Value = a.MyValue
  20. };
  21.  
  22. public IQueryable GetSomeData()
  23.  
  24. public class MyType {Key{get;set;} Value{get;set}}
  25.  
  26. public IQueryable<T> GetSomeData<T>() where T : MyType, new()
  27. { return from a in db.MyTable
  28. where a.MyValue == "A"
  29. select new T {Key=a.Key,Value=a.MyValue};
  30. }
Add Comment
Please, Sign In to add comment