Expression Trees are an abstract representation of code in a tree structure where each node of the tree represents a programming construct (conditional, assignment, method call, etc.)
Questions tagged [expression-trees]
2090 questions
1
vote
3 answers
Building an indexed expression from another expression
Scenario
public class Element {
public int Id {get;set;}
}
public class ViewModel {
public IList Elements{get;set;}
}
I have a method with a parameter of type Expression>,
which looks like m => m.Id
I'd like to…

Raphaël Althaus
- 59,727
- 6
- 96
- 122
1
vote
1 answer
Use an expression tree in an method inside another expression tree
I have two classes:
class Foo
{
string Name
}
class Bar
{
IList Foos;
}
And the following expression tree:
var fooFilters = (Expression>)(foo => foo.Name == "baz");
In NHibernate I can…

Ortiga
- 8,455
- 5
- 42
- 71
1
vote
1 answer
Linq to EF Expression Tree / Predicate int.Parse workaround
I have a linq Entity called Enquiry, which has a property: string DateSubmitted.
I'm writing an app where I need to return IQueryable for Enquiry that have a DateSubmitted within a particular date range.
Ideally I'd like to write something like…

Mark
- 448
- 1
- 4
- 12
1
vote
3 answers
C#, Linq to Sql: Why can I not use an expression to filter SubEntities?
I have made myself an ExpressionBuilder class that helps me put together expressions that can be used as a predicate when doing Linq to Sql queries. It has worked great. However, I just discovered Expressions can only be used to filter on Tables,…

Svish
- 152,914
- 173
- 462
- 620
1
vote
1 answer
Field Setter/Getter using Delegate
This is my simple test code. I want to create field assignment link between 2 objects, and the field is determined at runtime using reflection by caching delegate of its setter/getter method. But, somehow it doesn't work. The assignment is not…

uray
- 11,254
- 13
- 54
- 74
1
vote
1 answer
Extension Method for Entity Framework 4
I use an extension method for entity Framwork entity:
Public Function IsExcluded(ByVal item As AnomalyProduct) As Boolean
Dim result As Boolean
If (item.WholesalerProductCode IsNot Nothing) AndAlso…

Exatex
- 359
- 2
- 11
1
vote
1 answer
Combining Linq Queries with ANDs or Ors
I have a problem as depicted below:
var customers = from c in ctx.Customers;
Dynamically from UI, I can pass a list of filters
Scenario 1. "AND"
groupOp = "AND"
filter 1: where c.ID == 1
filter 2: where c.Name == 'XYZ'
What I need is a way to…

chugh97
- 9,602
- 25
- 89
- 136
1
vote
1 answer
Linq to sql expression tree execution zone issue
I have got a bit of an issue and was wondering if there is a way to have my cake and eat it.
Currently I have a Repository and Query style pattern for how I am using Linq2Sql, however I have got one issue and I cannot see a nice way to solve it.…

Grofit
- 17,693
- 24
- 96
- 176
1
vote
1 answer
Refactoring of decision trees using automatic learning
The problem is the following:
I developed an expression evaluation engine that provides a XPath-like language to the user so he can build the expressions. These expressions are then parsed and stored as an expression tree. There are many kinds of…

rph
- 2,104
- 2
- 13
- 24
1
vote
0 answers
LINQ and VB.NET and the expression tree that is compiled is breaking SubSonic 3
I've been trying to solve a little problem with VB.NET and the expression trees it likes to generate.
I have a simple test...
Public Sub ActiveRecord_Find_By_NonKey_Returns_123()
Dim orders = Order.Find(Function(item As Order) item.EmployeeID =…

BlackMael
- 3,198
- 5
- 25
- 42
1
vote
1 answer
How do I build a repository method that builds an Expression using a passed in parameter?
I have a repository where several methods are using the same piece of logic within the predicate.
public IList GetLoansByCommitmentID(int commitmentID)
{
var query = this.context.Loans.Where(l => l.CommitmentLoan != null &&
…

Rawlins
- 61
- 7
1
vote
1 answer
Nested property in Expression tree
I want to write an expression that will retrieve a property within a property. My 2 classes:
public class BusinessType
{
public string Proprietor
{
get { return "Proprietor"; }
}
}
public class VendorApplicationViewModel
{
…

Kai CriticallyAcclaimed Cooper
- 958
- 2
- 15
- 27
1
vote
1 answer
Generic Repository Linq2Sql impedence mismatch problem
I am working on a repository pattern where the API look as follows:
var visitor = repository.Find(x => x.EmailAddress == credentials.EmailAddress &&
x.Password == credentials.Password);
where visitor is a domain object…

Michael Mann
- 777
- 3
- 9
1
vote
3 answers
Given two generic type variables, how do I compile a system.linq.expression tree to multiply them?
Given two generic type variables, how do I compile a system.linq.expression tree to multiply them? It's perfectly acceptable if the expression throws an exception if the two types do not have a valid operator * between them.
I chose…

Narf the Mouse
- 1,541
- 5
- 18
- 30
1
vote
1 answer
Building expression tree with LINQ Min method - throws ArgumentException
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Test_console_application
{
class Program
{
static void Main(string[] args)
{
var…

Morten Holmgaard
- 7,484
- 8
- 63
- 85