Convert linq query to lambda

  • Thread starter Thread starter Sems
  • Start date Start date
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);
 
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.
 
Back
Top