score:2
Accepted answer
first of all, why single
? must there be only one object with the given name
and must you enforce it in this specific code? bear in mind that single
is expensive because it will enumerate the whole collection to make sure the found object is unique.
if you are just interested in finding the first, if any, then simply use the aptly named first
extension method:
models.first(m => m.name == stringtofind);
ok, so that returns the first object with a given name
, if any, you simply need to filter the fields
proyerty:
var pair = models.first(m => m.name == stringtofind)
?.fields
.first(f => f.key = keytofind);
Source: stackoverflow.com
Related Query
- Find object in list with given property value then find dictionary value
- Using LINQ, how do I find an object with a given property value from a List?
- How to find how many times the same object appears in a list and then find a property of the most appeared object
- Using Linq find first object in list sorting by property A, then property B
- LINQ: Given A List of Objects, Create a Dictionary with child objects as keys and Parent Objects as Value
- Find the List index of the object containing the closest property value
- Need to return an object with the lowest property value from List of objects
- How to find all items in a list where a property has a specific value or where there is a related item with this value?
- How to get the property from a list of object that is a string with the lowest numeric value
- How can I find the first items in a list with a different value for a property using Linq?
- Dictionary lookup with LinQ to find a subset where the Value is a List element
- How to use LINQ to select object with minimum or maximum property value
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- LINQ - Convert List to Dictionary with Value as List
- How to get/find an object by property value in a list
- How can I find object in List with Linq?
- How to find key value pair in a dictionary with values > 0 with key matching a certain string pattern?
- Count number of given object in a list with LINQ
- Find all classes with an attribute containing a specific property value
- C# LINQ selecting a list with a property that has multiple value
- I am trying create a new list of users from a list of users who have not created an additional object with a certain property using LINQ
- How to make a SUM of Dictionary Value nested into a list with LINQ?
- Linq: Convert list of object to dictionary, with an object member as value
- How to find same classes in a list with one different value
- Find closest value in an array List with linq?
- Return list with more than one value stored in a dictionary using linq
- c# find item in list returned by LINQ query and compare its value with another item in list
- Get minimum and maximum time value from list of object property using Linq
- LINQ query to filter list by object property with multiple checks
- How to convert dictionary with object to list of that type?
More Query from same tag
- Search in IQueryable<object>
- Linq retrieve a summary list in a query
- LinQ Grouping records with null values
- How to order and groupby while maintaining list order using Linq
- How can I assign a multiple column in my sql tables to single column in my List<>
- Dynamic Linq Select
- XML with sub nodes to csv format using linq
- LINQ Select from sub-list
- C# Ef Core Linq Query adding a calculated field to existing query results without using model
- C# no coercion operator is defined between types anonymous object
- Split datatable into multiple fixed sized tables
- Issue in Linq to object where clause : the condition is bypassed
- Convert string to LINQ query
- How can I dynamically change the condition of where, depending on the parameter
- Simplifying Linq to Object result
- Skipping rows in results is not currently supported
- Group by one field and also get others fields
- Linq: Group on list inside lists
- Hashing an expression tree
- How to find the max id of any table.
- Check if queryable is null before assigning a list
- Method to get a summary view from a dataset
- Merge two dynamic lists and override values
- Issue with LINQ to XML
- LINQ distinct by 2 properties and by create date
- beginner to linq to entity sql: How do I write this linq to Entity query
- Linq join list and table
- LINQ to SQL Storing query results in a variable
- Replacing last characters with a character
- Read console input as enumerable - one statement?