score:5
You need to use SelectMany
to concatenate result sets.
var items = employees.SelectMany(e => e.Orders.Select(o => new Item(e.ID, o.ID)));
score:3
The extension method you're looking for is called "SelectMany": http://msdn.microsoft.com/en-en/library/system.linq.enumerable.selectmany.aspx
score:3
Have a look at Enumerables.SelectMany()
, see the example in this Stack Overflow question.
score:5
For what it's worth, this can be written somewhat more succinctly and clearly in LINQ syntax:
var s = from e in employees
from o in e.Orders
select new Item(e.ID, o.ID);
Source: stackoverflow.com
Related Query
- Convert string[] to int[] in one line of code using LINQ
- Convert simple SQL group-by into LINQ to SQL
- LINQ Source Code Available
- Simple LINQ question in C#
- Cannot convert source type to target type List<KeyValuePair> Linq
- Simple LinQ question: convert [][] to []
- Convert simple ForEach into a Linq statement
- convert foreach loop to linq code
- creating Linq to sqlite dbml from DbLinq source code
- Does LINQ convert code to SQL queries
- How do i convert this linq code to inline sql
- Simple LINQ question - how to iterate through a group?
- Simple C# foreach to LINQ question
- How to convert this recursive code to Linq
- Grouping in LINQ - simple question
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- convert linq to object query to sql query (no linq to sql code or datacontext)
- Convert piece of code into LINQ (short syntax)
- My code is very inefficient for this simple Linq usage
- Convert code that uses Linq to code that does not
- LINQ A simple question
- Linq - how to convert this code to linq
- Can I can convert this C# code into some Linq code?
- Simple Linq Dynamic Query question
- source code for LINQ 101 samples
- Convert simple Left Outer Join and group by SQL statement into Linq
- Convert VB.NET Linq to C# Linq code
- Simple Linq to XML question
- Convert SQL code to linq (LIKE, SELECT)
- convert recursive code to LINQ
More Query from same tag
- How can i insert a new object to anonymous array?
- linq using order by, where, and select vb.net
- Generic Grouping Using Linq
- How to set Filter Values in LinQ with SQL Query Text?
- Cannot return linq result from query
- Query Object Pattern vs LINQ
- How to use LINQ to return substring of FileInfo.Name
- Fetch distinct record from datatable using linq to datatable and shows all columns of datatable
- Query in LINQ TO SQL not inserting
- Get IQueryable<T> where any field of T contains a given string
- Make Math.Log work in an Entity Framework Query
- Linq problem with group by clause
- LINQ to SQL Join issues
- Linq select join razor page display
- Can we use Linq to sort a class based on its ID without implementing IEnumerable
- linq store select clause as function variable
- LINQ to DataTable, finding duplicate rows
- asp.net linq query datatable
- LINQ approach to parse lines with keys/values
- Combining Where and OrderByDescending Using a Custom Method
- LINQ group by and SUM
- ForEach extension method
- Iterate data in anonymous variable
- Why didn't the LINQ designers stick with using the way sql is written today?
- LINQ to SQL entity column name attribute ignored with guid primary key
- Entity Framework 6.1.3: Projection - load children of children directly
- Ugly LINQ statement, a better way?
- Linq: select parent based on sub collection
- Getting characters from indices in list of strings into one list of characters
- Syntax error when performing OrderBy<T> on an IEnumerable List