score:2
Accepted answer
You got really close.
Your idExpression is an Expression in the form of x => x.Property
. However, you're passing the whole expression to the Equal expression. Change that to pass only the body:
var idEqualExpression = Expression.Equal(idSelector.Body, selectedValueConstant);
Then you can compile the lambda and pass it to FirstOrDefault without casting to a queryable:
var selectedSourceItem = source.FirstOrDefault(lambda.Compile());
Source: stackoverflow.com
Related Articles
- How to pass LinQ Expressions from F# to C# code
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- Linq extending Expressions
- Stubbing Code for Test With Linq Expressions and Lambdas
- Extending LINQ Expressions
- source code for LINQ 101 samples
- Make VB code that replaces LINQ expressions
- c# can I type the code I want to execute in LINQ expressions
- Implicit operators, Linq and Lambda expressions can make code less readable. But what is more readable?
- c# Linq or code to extract groups from a single list of source data
- Saved projection expression for re-use in different linq expressions with two source objects
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- Using GroupBy, Count and Sum in LINQ Lambda Expressions
- How are people unit testing code that uses Linq to SQL
- Extending LINQ to accept nullable enumerables
- Does C# 7 allow to deconstruct tuples in linq expressions
- How can I reuse expressions within LINQ statements?
- How do I combine LINQ expressions into one?
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Combine two Linq lambda expressions
- How to make LEFT JOIN in Lambda LINQ expressions
- Extract sql query from LINQ expressions
- Adding OR expressions in a loop in Linq
- Using LINQ expressions in Visual Studio's Watch window
- Syntax to execute code block inside Linq query?
- How do I compose existing Linq Expressions
- What is the difference between LINQ query expressions and extension methods
- Select() dropping items
- Cannot get Linq syntax to work
- C# - Search in List with array in WHERE clause
- Using LINQ in JArray
- LINQ, get string list using dynamic field name
- Linq to Entities "does not recognize the method ... method, and this method cannot be translated into a store expression."
- Best way to assign a value to a property of all objects in a collection using LINQ
- LinQ query with multiple tables and extracting data
- How can I group/sum values in LINQ to XML?
- Newtonsoft JArray - Select Multiple Values from Array specificed by node
- .Net Linq DataSet Problems (left outer joins)
- Joining Two list using LINQ Query and displaying only relevant data
- Improving SQL query generated by LINQ to EF
- Linq PredicateBuilder multi criteria
- Assign values from one list to another using LINQ
- How to transfer list as a parameter to query in Entity Framework?`
- Select IEnumerable<object> from IEnumerable<IEnumerable<object>> linq
- grouping the list object with where clauses and return
- Is there an equivalent for Enumerable.Empty<T> that returns IQueryable?
- Linq query - List within another list