I'm trying to merge two generic list using LINQ-
List<LinkedTable> FirstLink
List<LinkedTable> SecondLink
As shown in the Class below, my generic list itself has a generic list in it.
public class LinkedTable
{
public string TableId { get; set; }
public string TableName { get; set; }
public List<Link> innerLinks { get; set; }
}
public class Link
{
public Boolean linkFlag;
public string Descriptor { get; set; }
public string RecordId { get; set; }
}
When I merge the two lists, the new list doesn't contain both the "innerLinks" records of FirstLink and SecondLink. I have tried the following code:
FirstLink = FirstLink.Concat(SecondLink)
.GroupBy(e1 => e1.TableId)
.Select(e2 => e2.FirstOrDefault())
.ToList();
Now FirstLink will get all the Tables grouped by "TableId ", but a few "innerLinks" from SecondLink is missing.
I need both the list of "innerLinks" from FirstLink and SecondLink in the new merged List without repetition.
Example:
FirstLink[0].innerLinks[0]
.innerLinks[1]
.innerLinks[2]
SecondLink[0].innerLinks[1]
.innerLinks[2]
.innerLinks[3]
Merged Link should be:
FirstLink[0].innerLinks[0]
.innerLinks[1]
.innerLinks[2]
.innerLinks[3]