score:3
Lets break apart your query:
BaseClassContainerCollection.Single(yourPredicate);
Single
, as it is used here, basically says "filter BaseClassContainerCollection on this predicate" (a "filter" function that evaluates to true or false for whether or not to include it in the results). Instead of a function that returns true/false, you're saying you want it to evaluate to a MyBaseClass, which doesn't make sense. Your inner call to Single
makes sense, because x => x.Id == guid
is a function that returns true/false and filters to only those elements that meet the criteria (then states that you know there will only be one of them in the results or else throw an exception).
What you want to do is Select
the single MyBaseClass result from the inner query, then call Single on the result (without a predicate) since you know the result should only have one item returned. I believe you're looking for:
BaseClassContainerCollection.Select(container => container.BaseClasses.Single(baseClass => baseClass.ID == specificGuid)).Single();
Source: stackoverflow.com
Related Articles
- Use LINQ to select Single from nested collections
- c# Linq or code to extract groups from a single list of source data
- Select single column from dataset with LINQ
- Select object from nested collection using Linq
- Linq query to select single string from multiple List<string>
- Linq to select list of items from custom nested list of objects
- creating Linq to sqlite dbml from DbLinq source code
- Linq query, how to build nested objects from single table
- Linq - Select single item from child collection
- select single value from linq
- Get specific value from nested collections using LINQ
- Select distinct list from nested collections on multiple fields
- LINQ Select from two Collections with same length
- How to use Linq in C# to select a specific string from multiple nested columns?
- Select a single child item from child collection in LINQ
- How can I return a single value integer from Linq from an array of objects that have other nested values
- LINQ conditional select from table and return multiple column as a single list
- Simple Linq query to select from a single item
- LINQ - Select correct values from nested collection
- Linq query from multiple sets of nested collections
- How to read data from a nested select query linq
- Dynamic Expressions LINQ Select - SelectMany from nested collection
- How to get data using select from a nested properties - linq
- Linq on XML get value from nested elements in select
- How to send a single json response from a vb.net linq query using the select option
- Linq Select Many from nested list
- Select Multiple Fields from List in Linq
- LINQ Using Max() to select a single row
- Linq code to select one item
- How to select values within a provided index range from a List using LINQ
- How to get a dictionary with Linq where keys are met more than once?
- How to properly make a LINQ query with clauses based on complex calculated data
- LINQ: returning 2 SELECTs in 1 IQueryable for pagination? Keeping in lines with the repository pattern and not changing the return type
- Group and Count using LINQ
- LINQ distinct on class item?
- Group multiple rows containing index and create list of custom objects for each index
- Learning the Entity Framework
- Convert Short? to System.Collection.Generic.List
- Better way of searching through lists than using foreach
- C# linq left out join does not work using DefaultIfEmpty
- Linq Error A second operation started on this context before a previous operation completed
- How can I get percentage in LINQ?
- How to use "Contain" in List?
- Specify condition with FirstOrDefault (in Method Chaining Approach)
- Order by one element and return multi properties in the same LINQ query
- How to retrieve a list of distinct values from a list within a list
- How to join two tables in linq and not get anonymous type result set
- Can't do multiple selects on a table for columns
- Select returning only one element
- Joining of two queries and returning in list format