score:2
I think you want to use Expression.AndAlso
(a short-circuiting AND) on the two predicate expressions in question to construct the body of the expression-tree.
var body = Expression.AndAlso(keyExists, valueCorresponds);
return Expression.Lambda<Func<Address, bool>>(body, dataFields);
EDIT: (If you want to stick with your existing technique)
My guess is that your And
method is an extension-method from the LINQKit library. If so, note that this extension involves 'invoking' the right-hand side expression with the parameters of the first expression as part of producing the result. If this isn't acceptable to you (LINQ provider limitations, perhaps?), you can use the useful Expand
extension that also comes with this library to 'inline' the invoked expression.
return Expression.Lambda<Func<Address, bool>>(keyExists, dataFields)
.And(Expression.Lambda<Func<Address, bool>>(valueCorresponds, dataFields))
.Expand();
But this is massive overkill in this case; my advice is to go with my first sample.
Source: stackoverflow.com
Related Articles
- Dynamically compiling LINQ queries to verify a dictionary value
- LINQ - Convert List to Dictionary with Value as List
- Dynamically generate LINQ queries
- Linq Query Dictionary where value in List
- Building Dynamic LINQ Queries based on Combobox Value
- LINQ Source Code Available
- LINQ Sub-select from Dictionary based on value type
- how to change the value of dictionary using linq based on key?
- minimum value in dictionary using linq
- Select most frequent value and count using LINQ and assign to dictionary
- LINQ querying nested dictionary with multiple key value selection in C#
- Update a Dictionary value using Linq
- Return list with more than one value stored in a dictionary using linq
- creating Linq to sqlite dbml from DbLinq source code
- Does LINQ convert code to SQL queries
- C# - Code supposed to be unreachable when calculate value in LINQ sum method
- C# LINQ : Dynamically create property and values that includes sum of a value from a grouped query
- build linq queries dynamically
- LINQ filter by type on list from dictionary value
- Dictionary of dates and values, finding value of max date per year in LINQ
- how to remove half of the dictionary items based on value (DateTime) with LINQ in C#?
- Linq return WhereEnumerableIterator from Dictionary value matches?
- Dictionary from other dictionary grouping by object value field using linq
- How to get value from Dictionary to new Object in LINQ query
- Linq query for dynamically value
- Can't add a new record with an integer value into database by using linq from code C#
- How to dynamically get a property value in which is in another property with Linq where statement
- Get Dictionary value in IQueryable LINQ to Entities query
- How to dynamically build and store complex linq queries against a list of hierarchical objects?
- Remove multiple keys with same value data from dictionary in C# using Linq
- How to loading XML files from a file
- LINQ: How do I select unique rows: max(id) with multiple columns?
- What is LINQ equivalent of SQL’s "IN" keyword
- C# Linq - Elegant way to order a dataset by the maximum value between two columns?
- how can i call the delete store procedure in linq query
- Error 6046: Unable to generate function import return type of the store function
- Storing XML in a nested dictionary
- Use of LINQ to select a subset of option chains
- LINQ where query on a JToken
- Is there anyway to return int and null with nested conditions?
- VB.NET and LINQ. What am I missing here?
- RavenDB, LINQ, select from string[] where array does not contain a given string
- Two way binding in WPF trough LINQ to SQL for the property of a ListItem of a ListBox using a DataTemplate
- Combining Where and OrderByDescending Using a Custom Method
- Unable to create a constant value. Only primitive types
- Xml Linq, removing duplicate nodes in XElement C#
- LINQ - How do I guarantee only one matching entry returned satisfying a certain criteria?
- LINQ query help
- How to assign "var" inside if statement
- Writing a recursive query and join with another list