score:1

Accepted answer

I would do:

var DRows = from inputRow in inputTable.AsEnumerable()
                 where inputRow.D == 'some value'
                 select new outputRow(inputRow, *delegateToProcessor*)

var ERows = from inputRow in inputTable.AsEnumerable()
                 where inputRow.E == 'some value'
                 select new outputRow(inputRow, *delegateToProcessor*)

var FRows = from inputRow in inputTable.AsEnumerable()
                 where inputRow.F == 'some value'
                 select new outputRow(inputRow, *delegateToProcessor*)

return DRows.Union(ERows).Union(FRows);

score:0

The select statement of linq can only select 1 object at the time. You could however select a group and afterwards do a union.
The result would look something like this :

        public static void test()
        {
            var data = new List<String>{"a","b","c","d"};
            var outputRows = from inputRow in data
                             select Expand(inputRow);
            var result = new List<String>();
            outputRows.ToList().ForEach(r=>result = r.Union(result).ToList());
        }

        private static List<String> Expand(string data)
        {
            var subdata = new List<String>();
            subdata.Add(data + "1");
            subdata.Add(data + "2");
            return subdata;
        }

score:0

what about this:

private IEnumerable<OutputRow> BuildOutputTable(DataTable inputTable)
{
    var tmp = from inputRow in inputTable.AsEnumerable()
              select new { x = getProcessedRows(inputRow)};
    var outputRows = tmp.SelectMany(x=>x.x);
    return outputRows;
}

private IEnumerable<OutputRow> getProcessedRows(YourInputRowType inputRow)
{
    List<OutputRow> ret = new List<OutputRow>()
    /* some logic here to generate the output rows for this input row */
    return ret;
}

score:2

Create a function like this:

public IEnumerable<OutputRow> GetOutputRows(InputRow input)
{
    if ( ** some condition on input.D ** )
        yield return new OutputRow(inputRow, *delegateToProcessor*);
    if ( ** some condition on input.E ** )
        yield return new OutputRow(inputRow, *delegateToProcessor*);
    if ( ** some condition on input.F ** )
        yield return new OutputRow(inputRow, *delegateToProcessor*);
}

and your query goes like this:

var outputRows = from inputRow in inputTable.AsEnumerable()
                 from row2 in GetOutputRows(inputRow)
                 select row2;

Related Articles