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
1 answer
Why doesnt my Expression Tree recognize my custom method?
I recently posted a question on how to write customized expression tree (though I didn't realize that was what I was asking at the time). Now I am trying to use the answer provided by Scott Chamberlain to create another generic method.
I am using…

bsayegh
- 990
- 6
- 17
1
vote
3 answers
Execute a linq tree expression into a where
This is my scenario: I need to extract data from an entity using an "OR" query on a a property in a linked entity.
These are my entities:
public class Dealer
{
public virtual int id{get;set;}
public virtual string name{get;set;}
public virtual…

Albirex
- 283
- 1
- 2
- 13
1
vote
3 answers
Python: Optimizing, or at least getting fresh ideas for a tree generator
I have written a program that generates random expressions and then uses genetic techniques to select for fitness.
The following part of the program generates the random expression and stores it in a tree structure.
As this can get called billions…

Peter Stewart
- 2,857
- 6
- 28
- 30
1
vote
1 answer
Dynamic Lambda Select Index
I need some help with a LINQ extension that I'm tying to write. I'm trying to create an extension that calculates the row index of a given Id within an IQueryable - Except that type can be any table. I think I've got most of the way there but I just…

Shawn Crane
- 43
- 1
- 7
1
vote
2 answers
Transform a delegate to a Expression Tree
I wonder if you can create and modify a Expression Tree out of a existing delegate.
Kinda like
public void Foo() {
Console.WriteLine(1000);
}
....
Expression exp = Foo.GetExpression();
//Now do something what changes 1000 to 2000...
So I…

Rico
- 11
- 1
1
vote
2 answers
How to get the reference to newly constructed instance in expression tree c#
Is It possible to get the reference to the PositionViewModel in the following expression tree:
public static Expression> ToViewModel
{
get
{
return x => new PositionViewModel
{
…

user3049133
- 229
- 1
- 4
- 12
1
vote
1 answer
Is there an inverse operation to Expression.Lambda?
Is there an inverse operation to Expression.Lambda<...>(originalExpression, parameterExpression) that would return me the original expression?
Context:
I am creating a lambda expression using the lambda syntax (not using the Expression class at all)…

Tomas Grosup
- 6,396
- 3
- 30
- 44
1
vote
3 answers
Expression.Assign to assign Expression.Call to Expression.Variable
I have seen a number of similar posts and it seems as though the var1 I have declared seems to need to be passed in elsewhere, but I can't seem to figure it out.
public Expression> CreateEqualNameExpression(string match)
{
…

peinearydevelopment
- 11,042
- 5
- 48
- 76
1
vote
2 answers
Inlining contents of an ILEmit DynamicMethod into an expression tree
I have a method which generates a DynamicMethod using ILEmit, and I want to inline its contents inside an expression tree. I need to do this in order to write the expression tree to an assembly.
I can compile the DynamicMethod and include that into…

Craig Gidney
- 17,763
- 5
- 68
- 136
1
vote
4 answers
C# Expression syntax
I was thinking about the difference between Expression> and Func<>, and wondered if you could convert a static method to an expression tree as follows:
class Program
{
static void Main(string[] args)
{
Func t = x =>…

cwa
- 1,092
- 9
- 12
1
vote
1 answer
DbContext get IQueryable for scalar system functions (Count, Any, Sum, Max)
I have DBContext with DbSet called Assignments.
It's not a problem to create queryable for enumerable expressions and concatenated them, however I don't see the way to get IQueryable with deferred execution for functions like Count, Any, Max,…

Philipp Munin
- 5,610
- 7
- 37
- 60
1
vote
1 answer
How do I subscribe to an event of an object inside an expression tree?
Sorry I couldn't think of a better title. This is a two part question that only make sense together.
Say I have a constructor like this
public Fact(INotifyPropertyChanged observable, Func predicate)
{
this.predicate = predicate;
…

firefly
- 285
- 3
- 12
1
vote
1 answer
How to get MemberInfo of ArrayLength type expressions?
Some trouble with UnaryExpressions.
This works this way:
Expression, object>> k = l => l.Count;
//got member in this case like this
var member = ((k.Body as UnaryExpression).Operand as MemberExpression).Member;
In the above case…

nawfal
- 70,104
- 56
- 326
- 368
1
vote
2 answers
Dynamic built Linq to SQL Query
i want to build a generic search window using linq to sql.
This is what i was trying to do:
class SearchWindow : Form : Where T: class
{
public SearchWindow(Func codeSelector,
Func nameSelector)
…

albertein
- 26,396
- 5
- 54
- 57
1
vote
1 answer
Where clause using Expression tree builder
I have to fetch data from database and filter data using the linq where clause.
My filter is an integer column and it contains value more than 1000.
What i am doing in the code is, breaking this huge array into chunk of 1000's of each and putting it…

Bhaskar
- 4,189
- 4
- 26
- 20