Convert linq query to lambda

S

Sems

Hi

I have the below linq query but want to convert it to use a lambda expression but can't figure it out. How should I do this?

Working query...

var d = from p in dictionary.Fields
where p.VariableName == SrcField
select p.Value;

Lambda attempt that is wrong...

var o = dictionary.Fields.Select(q => q.Value).Where(s => s.VariableName == SrcField);
 
U

Ulrik Magnusson

Lambda attempt that is wrong...    
           var o = dictionary.Fields.Select(q => q.Value)..Where(s => s.VariableName == SrcField);

try

var o = dictionary.Fields.Where(s => s.VariableName ==
SrcField).Select(q => q.Value);

in your attempt, the Where query operates on the result from
the Select query - you want the Select query to operate on
the result from the Where query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top