Guest User

Untitled

a guest
Dec 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. TableA
  2. string Name
  3. string Description
  4.  
  5. TableB
  6. string Name
  7. string Value
  8.  
  9. public MyObject
  10. {
  11. string Name
  12. string Description
  13. List<string> Values
  14. }
  15.  
  16. var tableA = _oda.GetTableA();
  17. var tableB = _oda.GetTableB();
  18. var model = from a in tableA
  19. join b in tableB on a.NAME equals b.NAME
  20. select new MyObject
  21. {
  22. Name= a.Name,
  23. Description = a.Description,
  24. Values = "<Not sure to get list of tableb.Value>"
  25. };
  26.  
  27. var tableA = new List<TableA> { new TableA { Name = "1", Description = "D1" }, new TableA { Name = "2", Description = "D2"} };
  28. var tableB = new List<TableB> { new TableB { Name = "1", Value = "V1" }, new TableB { Name = "1", Value = "V2"} };
  29.  
  30. var result = tableA.Join(tableB, a => a.Name, b => b.Name, (a, b) => new { A = a, B = b})
  31. .GroupBy(k => k.A, e => e.B.Value)
  32. .Select(g => new MyObject
  33. {
  34. Name = g.Key.Name,
  35. Description = g.Key.Description,
  36. Values = g.ToList()
  37. });
  38.  
  39. foreach (var res in result)
  40. {
  41. Console.WriteLine("Name: {0}, Description: {1}, Value: {2}", res.Name, res.Description, string.Join(", ", res.Values));
  42. }
  43.  
  44. var result = from a in TableA
  45. join b in TableB on a.Name equal b.Name
  46. group b.Value by a into g
  47. select new MyObject
  48. {
  49. Name = g.Key.Name,
  50. Description = g.Key.Description,
  51. Values = g.ToList()
  52. }
Add Comment
Please, Sign In to add comment