What I’m trying to achieve is a list of strings from multiple tables. I currently have a simple database structure with a ParentTable with 2 child tables, (Let’s say Child1 & Child2).
Both Child1 & Child2 have a column of type nvarchar(50) called Name. Currently, I can perform multiple queries to achieve a single list of strings:
var myList = new List<string>();
myList.AddRange(Child1.Select(c1 => c1.Name));
myList.AddRange(Child2.Select(c2 => c2.Name));
OR
var myList = new List<string>();
myList.AddRange(ParentTable.SelectMany(x => x.Child1.Select (c1 => c1.Name)));
myList.AddRange(ParentTable.SelectMany(x => x.Child2.Select (c2 => c2.Name)));
My ultimate question is whether or not it is possible to consolidate it down into 1 query, even if it means using the Parent table?
You just need to use the
Concatoperator: