code_junkie

Linq-to-SQL ToDictionary()

Nov 11th, 2011
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. var query = from p in db.Table
  2. select p;
  3.  
  4. Dictionary<string, string> dic = new Dictionary<string, string>();
  5.  
  6. foreach (var p in query)
  7. {
  8. dic.Add(sub.Key, sub.Value);
  9. }
  10.  
  11. var dic = (from p in db.Table
  12. select new {p.Key, p.Value })
  13. .ToDictionary<string, string>(p => p.Key);
  14.  
  15. var dic = db
  16. .Table
  17. .Select(p => new { p.Key, p.Value })
  18. .AsEnumerable()
  19. .ToDictionary(k=> k.Key, v => v.Value);
  20.  
  21. var dictionary = db
  22. .Table
  23. .Select(p => new { p.Key, p.Value })
  24. .AsEnumerable()
  25. .ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
  26. ;
  27.  
  28. var dic = (from p in db.Table
  29. select new {p.Key, p.Value })
  30. .ToDictionary<string, string>(p => p.Key, p=> p.Value);
  31.  
  32. var dic = db
  33. .Table
  34. .Select(p => new { p.Key, p.Value })
  35. .AsEnumerable()
  36. .ToDictionary(k=> k.Key, v => v.Value);
Add Comment
Please, Sign In to add comment