Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TableA
- string Name
- string Description
- TableB
- string Name
- string Value
- public MyObject
- {
- string Name
- string Description
- List<string> Values
- }
- var tableA = _oda.GetTableA();
- var tableB = _oda.GetTableB();
- var model = from a in tableA
- join b in tableB on a.NAME equals b.NAME
- select new MyObject
- {
- Name= a.Name,
- Description = a.Description,
- Values = "<Not sure to get list of tableb.Value>"
- };
- var tableA = new List<TableA> { new TableA { Name = "1", Description = "D1" }, new TableA { Name = "2", Description = "D2"} };
- var tableB = new List<TableB> { new TableB { Name = "1", Value = "V1" }, new TableB { Name = "1", Value = "V2"} };
- var result = tableA.Join(tableB, a => a.Name, b => b.Name, (a, b) => new { A = a, B = b})
- .GroupBy(k => k.A, e => e.B.Value)
- .Select(g => new MyObject
- {
- Name = g.Key.Name,
- Description = g.Key.Description,
- Values = g.ToList()
- });
- foreach (var res in result)
- {
- Console.WriteLine("Name: {0}, Description: {1}, Value: {2}", res.Name, res.Description, string.Join(", ", res.Values));
- }
- var result = from a in TableA
- join b in TableB on a.Name equal b.Name
- group b.Value by a into g
- select new MyObject
- {
- Name = g.Key.Name,
- Description = g.Key.Description,
- Values = g.ToList()
- }
Add Comment
Please, Sign In to add comment