score:3
var mylistoftypea = new list<typea>();
// ...
var citems =
from a in mylistoftypea
from b in a.mylistoftypeb
from c in a.mylistoftypec
where c.someinteger > 100
select c;
the above is equivalent to calling the selectmany
linq function, but in my opinion it is significantly cleaner and easier to read.
doing it with linq functions (as already suggested by dmitry, though with some modifications):
var citems =
mylistoftypea.selectmany( a => a.mylistoftypeb )
.selectmany( b => b.mylistoftypec )
.where( c => c.somevalue > 200 );
score:2
you need to navigate all sublists, and that what from
can do for you.
var ta = new typea();
var alltypecsthatsatisfymycondition =
from tb in ta.mylistoftypeb // this will iterate to each item in the list
from tc in tb.mylistoftypec // this will iterate to each item in the *sublist*
where tc.someinteger > 100 // condition could be anything; filter the results
select tc; // when you select, you tell your iterator to yield return that value to the caller.
return alltypecsthatsatisfymycondition.tolist(); // to list will force the linq to execute and iterate over all items in the lists, and add then to a list, effectively converting the returned items to a list.
score:3
you can do it the following way using linq:
var mylistoftypea = new list<typea>();
// fill your list here
var typecs = from typea in mylistoftypea
from typeb in typea.mylistoftypeb
from typec in typeb.mylistoftypec
where typec.someinteger > 100
select typec;
score:4
something like this is what you're looking for i think:
var result = mylistoftypea.selectmany(b => b.mylistoftypeb.selectmany(c => c.mylistoftypec.select(x => x.someinteger > 100))).tolist();
Source: stackoverflow.com
Related Query
- Linq: Is there a way to search a list of list of objects for values that match a condition?
- is there a better way to write this frankenstein LINQ query that searches for values in a child table and orders them by relevance?
- Using LINQ how do you filter a list of strings for values that match the pattern "q1, q2" etc.?
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
- Linq for selecting elements from list 1 that exist on list 2 by comparsion between 2 properties values
- is there a way to say LINQ that list is sorted...?
- Search for matching objects in a list and assign values
- How to search a list of objects for a specific string attribute using LINQ in C#
- Writing a LINQ statement that will add values for each list element
- Get values from list that match BOTH attributes using c# LINQ
- Linq to Entities - limiting the results of a search form to only those results that match all choices for a many to many relationship
- Is there a way to search in Dictionary<int[], List<int> by values inside values faster than this code already does?
- Using linq to compare object values works for single object but not a list of objects
- LINQ query to find objects in list with equal values for one of their properties
- Compare sublist of a list for objects that change, in Linq
- How can I search a list of objects that contains a list of objects for the first entry that contains an element matching my search criteria?
- Quickest way to search for objects in a very large list by string C#
- Linq - get objects with a list property that does not contain values in another list
- Is there a way I can do a foreach that contains code in a LINQ expression?
- Is there a LINQ way of converting a generic list of objects to an X by Y matrix of the same type?
- Using LINQ to return a list of entities that match all values in a list passed in as a parameter
- Is there any way to filter a nested lists with a linq query, so that i end up with filtered list of adequatly filtered lists?
- Return list of rows that match a list of values using LINQ
- Linq search several properties of a class for a string match where some of the properties are a list of another class
- VB.NET Search for objects in list and parse values of found object to array
- C# linq finding all string values in a list there match in mongodb
- LINQ query to return distinct field values from list of objects
- Is there a LINQ function for getting the longest string in a list of strings?
- C#: Is there a LINQ way to create an array of objects given an array of constructor parameters?
- Using LINQ to Objects to find items in one collection that do not match another
More Query from same tag
- Error: the specified linq expression contains references to queries that are associated with different context
- Get all children of a node with Linq in VB.net
- Is there a Javascript equivalent of Array.prototype.find() that works on older browsers?
- c# linq with group by and join throwing exception
- How to convert LINQ query result to List?
- Is there a way to use LINQ to select a range of items based on an enclosing condition (i.e. not a simple WHERE clause)?
- Workaround for DefaultIfEmpty
- Argument Exception with ComboBox dictionary
- Trying to populate a combox box using LINQ in C# but not getting any results
- LINQ to Entities does not recognize the method 'System.Linq.IQueryable in nested select
- Grouping duplicate values in LINQ
- C# LINQ: 'variable 'x' of type referenced from scope '', but it is not defined'
- where condition in include, how?
- From SQL to C# LINQ
- Performing LINQ queries on a DataTable object
- Filter Both Parent And Child Collection
- How can i querying inheritance class with linq to EF
- Return updated object value from list of objects
- Any() linq query on XmlNodeList
- Linq Left Join with Lambda Count
- LINQ .Startswith or .Contains problems in VB.NET4
- Best searchable collection strategy for performance?
- Converting TSQL query to LINQ
- Return Guid From XLinq attribute value, or Guid.Empty if XElement/XAttribute not found
- Linq group by and count
- Merged parent/child data into a page containing massive viewmodel containing dozens of models - how?
- How to convert temp table with case statement SQL to Linq?
- Selecting distinct rows but always select the last one
- Is it possible to select the sum of a column, grouping by another column?
- LINQ Right Join