If you have a list and want to combine a sub-list for any SomeObject that has the same Id field, how do you do it? Here is an example of objects:
public class SomeObject { public string Name { get; set; } public int Id { get; set; } public List<KeyPair> ValuePairs {get;set;} } public class KeyPair { public string Key { get; set; } public string Value { get; set; } }
And this is an example of creating a list of layouts:
List<SomeObject> objects = new List<SomeObject>(); objects = new List<SomeObject>() { new SomeObject { Name="Rando Object 1", Id=5, ValuePairs=new List<KeyPair>() { new KeyPair { Key="TestKey1", Value="TestValue1" }, new KeyPair { Key="TestKey2", Value="TestValue2" } } }, new SomeObject { Name="Rando Object 2", Id=5, ValuePairs=new List<KeyPair>() { new KeyPair { Key="TestKey3", Value="TestValue3" }, new KeyPair { Key="TestKey4", Value="TestValue4" } } } };
What type of Linq or related query do you need to make in order to create a new SomeObject list that is combined based on any top level SomeObject that has corresponding Id fields; then combine the KeyPair list into one list. So you will have SomeObject Id = 5, and then four key pair values ββcombined from two different previous SomeObjects in the list. The name value can be excluded from the new object.
Any ideas? Thank you very much.
source share