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 Articles
- 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?
- How to select multiple values from a Dictionary using Linq as simple as possible
- LINQ select one bool from condition over multiple rows
- Using LINQ to select all from multiple tables
- Select from multiple list using LINQ
- Selecting Multiple Rows from DataTable using Linq
- 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
- Select N to N rows from database using 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
- Select from Multiple List inside cascading DropDownList using condition in Linq query c#
- Delete Rows from multiple tables using Linq web Api asp.net
- How to Select Multiple Fields from DataGridView using LINQ in C# WinForms
- how to select records from multiple table with max count value from one table using Linq in Asp.net MVC C#
- Return Rows with Unique and Duplicate values from dataTable using LINQ
- How to get rows of Data from Multiple Tables using LinQ To Entities
- How to extract particular columns values from multiple rows using linq
- Select distinct rows from two datatables using LINQ
- Select Multiple Fields from List in Linq
- How to solve error when getting max value in a row (EF Core Linq)?
- Where does this LINQ performance come from?
- Convert nested for-loops into single LINQ statement
- passing entity type as parameter in linq
- Why can't I query this range?
- LINQ Distinct(), but programmatically select a winner
- LINQ Recursive query in web api code
- If a Sum() value returns Null use 0, currently have it casting to a nullable double?
- how to use a method with 2 parameters in my lambda expression
- How to populate a list<list<T>> with 100 empty List<T>s without a loop?
- Can i convert from byte[] to String in Lambda?
- Return hierarchy from sql in lists in c# using linq
- SELECT DISTINCT LEFT([string],2) in LINQ
- Multiple Include and Where Clauses Linq
- nhibernate linq magic, display everything except one record
- How to GroupBy a part of DateTime using System.Dynamic.LINQ library
- using xml parent data in a LINQ select statement
- Validate an object using Func<T,bool>
- LINQ Expression accessing more fields
- Return last insert id with LINQ to EF