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;
Source: stackoverflow.com
Related Query
- Return multiple rows from a select new using linq
- How to return multiple rows using LINQ lambda expression from SQL Server 2014?
- How to select from multiple tables using LINQ using a union query to return only one column?
- Return list using select new in LINQ
- How to select multiple values from a Dictionary using Linq as simple as possible
- Using Linq to filter out certain Keys from a Dictionary and return a new dictionary
- LINQ select one bool from condition over multiple rows
- Using LINQ to select all from multiple tables
- Select from multiple list using LINQ
- Can't add a new record with an integer value into database by using linq from code C#
- Selecting Multiple Rows from DataTable using Linq
- How do I return a new object from a mocked repository using a LINQ Expression?
- How do I select multiple items from a database using LINQ
- Selecting Multiple Rows from DataGridView using Linq
- How to select mutiple rows from Entity using Linq
- Return Multiple Objects from a Single Record using LINQ to SQL
- Return data from multiple tables using LINQ Method Syntax
- LINQ conditional select from table and return multiple column as a single list
- Using Linq to filter out certain Keys from a Dictionary and return a new dictionary2
- How to return ICollection<object> from linq, when using select new object() {}
- Select N to N rows from database using LINQ
- Return class that contains a collection using select new in linq
- SELECT Unique rows from Datagridview using LINQ
- Insert multiple rows to SQL from DataSet using LINQ
- select multiple rows and edit those multiple rows in a table using linq asp.net mvc
- How to select multiple fields from a DataView and apply .Distinct() using LINQ
- Return select objects and only desired subvalues from a list of lists using LINQ
- Linq selecting from multiple joins and returning all rows even if a table doesnt return a match
- How to map multiple entities from LINQ query into a new entity using a common map method
- How can I return temporary columns in linq query : from p in dbx.Perons select new {false,Id}?
More Query from same tag
- jqwidgets grid Entity Framework LINQ paging
- Format value inside list
- Refactor two linq queries into one single query
- Reduce columns selected by EF Core
- Linq returned results as condition to another linq query
- Combining lists in linq
- Can I do this with LINQ?
- Information saved in memory when using pending request in LINQ
- How to compare 2 sets of arrays for distinct matches
- Create array of string on every nth element
- How to compare and merge lists using linq or moreLinq
- Custom extension method to simplify LINQ to SQL statement
- Get X records from complex LINQ query
- Decimal Precision Lost when saved to DB, C#. I am using Entity Framework
- Adding a column qualifier to many LINQ to SQL constructs at once
- Delete duplicate rows from datatable based on 2 columns in c#
- How to use 'Any' in AsQueryable methods?
- Linq: filter Ids from a list of class
- Concat/Union Tables in LINQ
- How to match case-sensitive username and password
- LINQ Or operator
- getting first element from nhibernate fetch collection
- Convert sql select to LINQ
- Translate nested select of oracle query to linq
- how to get a table data where should be checked in another table without joining using linq include or another way?
- linq inner join sub query and conditional select
- Random Top query in MongoDB using C# Linq
- Linq to entities if else condions in query
- Build a string from an EntityCollection
- How to query multiple entities at once?