PC Review


Reply
Thread Tools Rate Thread

Convert linq query to lambda

 
 
Sems
Guest
Posts: n/a
 
      13th May 2011
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);


 
Reply With Quote
 
 
 
 
Ulrik Magnusson
Guest
Posts: n/a
 
      13th May 2011
> 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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq Query and Lambda shapper Microsoft C# .NET 3 10th Feb 2010 09:16 PM
Need some more help with a linq query or lambda expression Tony Johansson Microsoft C# .NET 2 23rd Jan 2009 08:01 AM
need help to write a linq query or a lambda expression Tony Johansson Microsoft C# .NET 2 22nd Jan 2009 10:28 AM
What Lambda expression corresponds to this LINQ query? raylopez99 Microsoft C# .NET 25 6th Oct 2008 12:42 AM
linq vs lambda CSharper Microsoft C# .NET 2 1st Oct 2008 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 PM.