I have 2 lists :-
OrigFruitList.Add(new Fruit { Category = "Apple", SubCategory = "" });
OrigFruitList.Add(new Fruit { Category = "Apple", SubCategory = "Red Apple" });
OrigFruitList.Add(new Fruit { Category = "Apple", SubCategory = "Green Apple" });
OrigFruitList.Add(new Fruit { Category = "Orange", SubCategory = "" });
OrigFruitList.Add(new Fruit { Category = "Peach", SubCategory = "" });
OrigFruitList.Add(new Fruit { Category = "Grapes", SubCategory = "Green Grapes" });
OrigFruitList.Add(new Fruit { Category = "Grapes", SubCategory = "Black Grapes" });
OrigFruitList.Add(new Fruit { Category = "Bananas", SubCategory = "" });
NormalFruitList.Add(new Fruit { Category = "Apple", SubCategory = "" });
NormalFruitList.Add(new Fruit { Category = "Apple", SubCategory = "Red Apple" });
NormalFruitList.Add(new Fruit { Category = "Apple", SubCategory = "Green Apple" });
NormalFruitList.Add(new Fruit { Category = "Orange", SubCategory = "Blood Orange" });
NormalFruitList.Add(new Fruit { Category = "Orange", SubCategory = "Sweet Orange" });
NormalFruitList.Add(new Fruit { Category = "Peach", SubCategory = "" });
NormalFruitList.Add(new Fruit { Category = "Bananas", SubCategory = "" });
NormalFruitList.Add(new Fruit { Category = "Bananas", SubCategory = "Yellow Bananas" });
NormalFruitList.Add(new Fruit { Category = "Bananas", SubCategory = "Green Bananas" });
Now I wish to merge the second list, with LINQ if possible, depending on the first list.
For example there is only 1 entry for Orange in the Original List, and I wish to append the 2 entries from the Normal list to the Original list. Same goes for Bananas.
How can I achieve that with LINQ?
Thanks for your help and time
————RESULT I wish to achieve
//FinalResult
//Apple
//Red Apple
//Green Apple
//Orange
//Blood Orange
//Sweet Orange
//Peach
//Green Grapes
//Black Grapes
//Bananas
//Yellow Banans
//Green Bananas
Try this: