zzz projects Expression Tree Tutorial
Getting Started Documentation Knowledge Base
  • Getting Started
  • Documentation
  • Knowledge Base

Expression Tree Tutorial - Knowledge Base (KB)

21 results in tag: c#-4.0

Obtaining a parameterExpression's run-time value in an expression tree

I am missing the obvious: How do I access the value of a parameter inside a lambda expression expression tree? ...Scenario: For a delegate x I dynamically create a lambda expression with an expression tree body which has the same signature as the delegate...
c# c#-4.0 delegates expression-trees lambda
asked by dalo

What is the purpose of ExpressionVisitor.VisitT>?

Before someone shouts out the answer, please read the question through....What is the purpose of the method in .NET 4.0's ExpressionVisitor:...public static ReadOnlyCollection<T> Visit<T>(ReadOnlyCollection<T> nodes, Func<T, T> elementVisitor) ...My first...
c#-4.0 expression-trees expressionvisitor linq
asked by Jeff

In this expression tree, why am I getting a null reference exception?

I have a tree expression that looks like this:....Block( System.Object $instance, MyType2 $result) { $result = (MyType2)((MyType1)$instance).Property1; .Goto return { }; .Label .LabelTarget useDefault:; $result = .Default(MyTyp...
.net c# c#-4.0 expression-trees lambda
asked by Sandor Drieënhuizen

Expression trees in C# 4 are "dynamic."

I'm trying to figure out how to put all the pieces together, and would appreciate a concrete source code sample for a simple case to start with....Consider the following C# code:...Func<int, int, int> f = (x, y) => x + y; ...I can produce an equivalent fu...
c# c#-4.0 dynamic expression-trees
asked by Pavel Minaev

"Ambiguous Match Found" with Expression.Call

I'm trying to write an expression that will call ToString on a property and assign it's value to a local variable. However, calling ToString on a object instance w/ an overload of ToString, causes an exception of "Ambigous Match Found" to be thrown. Here'...
c#-4.0 expression-trees
asked by James Alexander

Linq to SQL Expression to Expression Tree Conversion

Can anyone convert this simple LINQ-to-SQL to an Expression Tree:...List<Region> lst = (from r in dc.Regions where r.RegionID > 2 && r.RegionDescription.Contains("ern") select r).ToList();
c#-4.0 expression expression-trees linq-to-sql
asked by Arian

Personalized expression

I found this example code:...public IQueryable<T> Get<T>(ObjectSet<T> obj) where T : class { Type type = typeof(T); var x = type.GetInterface("IMyInterface"); if (x != null) { var property = type.GetProperty("MyStringField"); ...
c#-4.0 expression-trees linq-to-entities
asked by bit

How can I acquire the value of a local variable-based ConstantExpression?

I created an ExpressionVisitor implementation that overrides VisitConstant. However, when I create an expression that utilizes a local variable I can't seem to get the actual value of the variable. ...public class Person { public string FirstName { ge...
c# c#-4.0 expression-trees
asked by devlife

Interval grouping using dynamic linq (DateTime, Numeric)

I search everywhere and didn`t find anwser for this question. I want to group by intervals (DateTime, Numeric) in Dynamic linq (the data will be crated dynamically so i must use dynamic linq)...Lets assume that we have such data:...ID|Date|Price 1|2010-1...
c#-4.0 dynamic-linq expression-trees lambda linq
asked by WebDeveloper

ERROR A static method needs a null instance, while a non-static method does not.

I am trying to create an expression tree. I need to read data from a data table and check its columns. The columns to be checked and also the number of columns to be checked are known at run time only. The column names are given to me as a string array a...
c#-4.0 expression-trees lambda linq static-methods
asked by Jani5e

In ExpressionVisitor, how do you evaluate an expression?

I need to use ExpressionVisitor to analyse an Expression before executing it. For my needs, i need to evaluate the right part of a Divide expression but i don't know how to do it. Here's a sample code that i have:...internal class RulesChecker : Expressio...
c# c#-4.0 expression-trees expressionvisitor lambda
asked by Alexandre Jobin

To use in expression trees, convert Funcstring, bool> to bool.

I've got an overly complicated binary expression tree building system It takes in a string and a pair of objects (Player and World)...Each node on the tree represents an external function that takes a string, player and world, and either returns a bool (...
c# c#-4.0 expression-trees
asked by bigjokerfish

How to use Expression Tree to build dynamic conditions

Please consider this code:...System.Linq.Expressions.Expression<Func<tbl, bool>> exp_details = r => r.ID_Master == Id && r.Year == Year && r.Month == Month ; ...I want to write a function that expect some argument, and then retrieve some data from my data...
c# c#-4.0 entity-framework expression-trees linq
asked by Arian

Why can't a named argument specification be found in an expression tree?

Using AutoMapper, I hit a place where a named argument would've fit very nicely:....ForMember(s => s.MyProperty, opt => opt.MapFrom(s => BuildMyProperty(s, isAdvanced: false))) ...But the compiler yelled at me:...An expression tree may not contain a named...
c# c#-4.0 expression-trees
asked by Brandon Linton

dynamic sort in linq

please consider this scenario:...I have a list of a class with about 50 fields.I want to have a Combobox that user can select according to what field list will sort.For example if user select "F1" list sort according to "F1"....I don't want to sort with ....
c# c#-4.0 expression-trees lambda linq
asked by Arian

Trying to filter on a Nullable type using Expression Trees

I have pasted my entire test app below. It's fairly compact so I am hoping that it's not a problem. You should be able to simply cut and paste it into a console app and run it. ...I need to be able to filter on any one or more of the Person objects' prope...
c#-4.0 expression-trees lambda linq
asked by Gary O. Stenstrom

How to convert Func<T,bool> to Expression<Func<T,bool>>

I have a Func like this :... Func<MyClass, bool> func = x=>Id == 5; ...How I can convert it to :... Expression<Func<MyClass, bool>>
c# c#-4.0 expression-trees lambda linq
asked by Arian

Expression Trees with dynamic parameter

I want to convert this:...Func<dynamic, object> myFunc = t => return t.Name + " " + t.Surname; ...Into an Expression Tree....What I have came up with, is this:...ParameterExpression target = ExpressionParameter(typeof(dynamic), "target"); ParameterExpress...
.net c# c#-4.0 dynamic expression-trees
asked by Matias Cicero

How to Convert Predicate to String and String To Predicate

I work on a special project that have to convert Predicates (or Expressions) to string and store on the database and retrieve it and convert it to Predicates and evaluate it because I want to change it in run-time. Please help me to imeplement ConvertStr...
c# c#-4.0 expression-trees lambda linq
asked by ArMaN

Making a lambda expression to call a method from a generic class

I have these simple interface:...public interface IQuery<TResult> { } public interface IQueryHandler<in TQuery, out TResult> where TQuery : IQuery<TResult> { TResult Handle(TQuery query); } ...And there are some implementation of them. I'm tryin...
c# c#-4.0 expression-trees func lambda
asked by ravy amiry

Page 1 of 2
  • 1
  • 2
  • ยป

Prime Library

Performance

  • Entity Framework Extensions
  • Entity Framework Classic
  • Bulk Operations
  • Dapper Plus

Expression Evaluator

  • C# Eval Expression
  • SQL Eval Function
More Projects...
Get monthly updates by subscribing to our newsletter!
SUBSCRIBE!