views:

76

answers:

1

I have the following code:

var columnNames = (from autoExport in dataContext.AutoExports
               where autoExport.AutoExportTemplate != null
                  && ContainsColumn(autoExport.AutoExportTemplate, realName)
               select GetDbColumnNames(autoExport.AutoExportTemplate, realName)).ToList();

Where the function GetDbColumns() returns an List<string>. So columNames is of the type List<List<string>>. Is it possible to create a List<string>, so each element of the list of GetDbColumns is added to the result of the LinQ query?

+1  A: 

You can use SelectMany:

var columnNames = (
    from autoExport in dataContext.AutoExports
    where autoExport.AutoExportTemplate != null
          && ContainsColumn(autoExport.AutoExportTemplate, realName)
    select GetDbColumnNames(autoExport.AutoExportTemplate, realName)
).SelectMany(x => x).ToList();
Aristoteles