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);

Related Query