score:18
Accepted answer
You don't need the lambda expression in the "where" clause - the query expression translation does that for you. Just use:
var result = from rangeVariable in DataSource
where Foo.MethodReturnsBoolean(rangeVariable) == true
select rangeVariable;
I would personally then remove the "== true" redundancy (I know this was only sample code, but...):
var result = from rangeVariable in DataSource
where Foo.MethodReturnsBoolean(rangeVariable)
select rangeVariable;
I'd then consider what using a query expression is actually buying you. If you're just doing a "where" (or just doing a "select") you may find dot notation simpler:
var result = DataSource.Where(x => Foo.MethodReturnsBoolean(x));
It gets even better though: the compiler doesn't need to infer a return value from the lambda expression (because it will always be bool
) so you can just use a method group conversion:
var result = DataSource.Where(Foo.MethodReturnsBoolean);
How much cleaner is that? :)
Source: stackoverflow.com
Related Query
- Linq Evaluating a method as a lambda expression
- Anonymous methods vs Extension method vs Lambda expression vs Linq
- Build LINQ Lambda Expression with contains method for enum property with list of int
- How to define in the lambda expression as another function in LINQ Select Method
- What is the best way to find length of split characters from the given string by using String.Split() Method or Linq Lambda Expression in C#
- C# Pass lambda expression field into method and use field in linq query
- Change lambda expression to a method - LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
- C# Pass Lambda Expression as Method Parameter
- "Or" equivalent in Linq Where() lambda expression
- LINQ - Query syntax vs method chains & lambda
- LINQ: Passing lambda expression as parameter to be executed and returned by method
- Like in Lambda Expression and LINQ
- What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?
- How to retrieve last 5 records using LINQ method or query expression in C#
- Selecting multiple columns with linq query and lambda expression
- How to Convert LINQ Comprehension Query Syntax to Method Syntax using Lambda
- LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression
- convert this LINQ expression into Lambda
- Can you reverse order a string in one line with LINQ or a LAMBDA expression
- What is equivalent to clause between, for comparasion strings in LINQ or lambda expression of?
- LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' method, and this method cannot be translated into a store expression
- C# linq expression in lambda with contains
- Comparison : LINQ vs LAMBDA Expression
- Concatenate two column values in LinQ Lambda Expression
- Using a LINQ ExpressionVisitor to replace primitive parameters with property references in a lambda expression
- Equivalent of SQL Between Statement Using Linq or a Lambda expression
- LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression
- LINQ naming Standard - Lambda Expression
More Query from same tag
- How to handle null in LINQ query for nullable int if value not found
- EF Linq include last
- max and min rates for the particular area -lambda query
- Customizing an XML element using LINQ To XML
- Get min DateTime from Linq
- Adding In and NotIn to System.Linq.Expressions.Expression, is it possible?
- Linq to Entities - Filter on any item in one list belonging to another list
- LINQ: Group by and Join
- How can I extend a field of a class?
- Has anyone done the Linq 101 samples with Lambda syntax?
- How do I use LINQ to Entities in Visual Basic?
- How can I compare two IEnumerable<> objects and return a new one?
- Get position of specific element in ordered table
- How to pass an async method as an action?
- Is there an algorithm or pattern to merge several rows of the same record into one row?
- LINQ methods executing sequence
- Cosmos DB: How to detect request charges with LINQ queries
- linq returning IEnumerable<{Object,Object}> from a function
- Linq not equal to returning all values in wpf datagrid
- Getting objects using LINQ and stored procedure
- LINQ for diffing sets
- How to apply search filtration based on AND condition using LINQ MVC
- LINQ .Take() returns more elements than requested
- Get the list of Child controls inside a groupbox
- Explicit construction of entity type 'tblpayment' in query is not allowed
- Displaying sequence numbers for the records in the DataTable and data binding is done through LINQ
- Left join in linq to entities null error
- Modify duplicate values with duplication index suffix (using Linq)
- C# Does Lambda => generate garbage?
- linq groupby and max count