Questions tagged [expression-trees]

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.)

Filter by
Sorted by
Tagged with
-1 votes
0 answers
27 views

Access property of an object using property name provided via Expression [duplicate]

I want to (a) provide a property name via an expression tree (b) and then receive the value of this property. I know how to do (a), at least how to get the property name as string: public class ...
stefan.at.kotlin's user avatar
1 vote
0 answers
28 views

How do I create multiple parameters PostgresFunctionExpression

I have a query select PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY "Order") as median How do I use this function in EF EF.Functions or defined function mapping? I try to define function ...
aisy's user avatar
  • 41
-1 votes
0 answers
27 views

C# NullReferenceException from Expression Tree used in EF Core query in a Generic Method [duplicate]

I have a generic method where I build a lambda expression and try to query a DB in EF Core. I am using a dictionary to hold the property and the constant forming a key pair of (property, constant) and ...
Charsace's user avatar
1 vote
2 answers
68 views

Can this function be modified to handle multiple property comparisons?

For reference, here is the original question (Keep in mind that the Filter() function originates from this post): Dynamic Where for List<T> Original post's function for clarity: public static ...
snappymcsnap's user avatar
  • 2,050
1 vote
1 answer
58 views

Dynamic LINQ Query-Builder is throwing an exception

I'm trying to query my DB-Entities with a Business-Class-Linq-Query. I know I need to transform the LINQ-Query so that it can run against the Entity-Class. My Problem is, that I can't figure out, why ...
Michael Rall's user avatar
1 vote
1 answer
55 views

How Do I Transplant and Execute User Code in a C# Source Generator?

I am creating a Roslyn .NET source generator. With it I am inspecting user code for lambda expressions given as an argument in a method call like this: // User Code MyLibrary.MyMethod<Guid>(k =&...
Jim Noble's user avatar
  • 492
0 votes
1 answer
27 views

Matching arguments with Moq.ItIs<expression tree>()

I don´t know how to pass a expression tree using the Moq.ItIs<> The type of the parameter is Expression<Func<Destination, bool>> But I don´t understand why I can´t pass something ...
partymetal's user avatar
6 votes
2 answers
89 views

C# Expression Tree AndAlso for Entity Framework query

I get an error when trying to combine two expressions with AndAlso. Step 1: building expression for EF object with expression tree: public override Expression<Func<T, bool>> ToExpression() ...
Carlos28's user avatar
  • 2,391
0 votes
0 answers
110 views

Use an Expression to fill out object property inside a Select clause

I have a specific Expression that is dynamically generated that I want to reuse in a Select statement that ultimately will be execute by EF Core as SQL in Postgres. So I am of course limited to ...
Fabian's user avatar
  • 439
0 votes
0 answers
20 views

Expression tree is not printing what it should

I'm coding an expression tree for school but it is not printing what it should. Can someone help me? package proyecto.pkg3; import java.util.Stack; public class ExpressionTree { private ...
Alex_Vargas's user avatar
0 votes
2 answers
131 views

How to create a tree structure from a logical expression?

I want to parse a logical expression like the following: (f = '1' OR f = '2') AND (s = '3' OR s = '4' OR s = '5') AND (t = '6') What I need, is a representation of this logical expression in the form ...
Ipsider's user avatar
  • 553
1 vote
1 answer
64 views

Recursive Expression Tree Parsing With Sprache

so i have a parser that uses use sprache to create an expression from a string. something like PhysicalAddress.State == "GA" has PhysicalAddress.State parsed as the left, == as the operator, ...
Paul DeVito's user avatar
  • 1,552
0 votes
2 answers
121 views

Build getters and setters lambdas to avoid using reflection in c#

I am validating a lot of complex objects in my applications. For example: public class School{ public string Name {get;set;} public DateTime DateCreated {get;set;} public List<Person > ...
Tono Nam's user avatar
  • 34.2k
0 votes
1 answer
134 views

Building an Expression tree for navigation property item in code

I am working with VS2022 and use EF Core. My data context is _myLab05Context, I have an entity "Solution" which has a navigation property "SolutionUsages". SolutionUsages has a ...
Hucky's user avatar
  • 29
0 votes
1 answer
63 views

Why can't EF translate this Expression when it's derived from a virtual property?

I want to define an Expression<Func<TSource,TKey>> KeyExpr such as you would pass to IQueryable.OrderBy, and then combine it with a TKey value to derive an Expression<Func<TSource,...
Kevin Krumwiede's user avatar
0 votes
1 answer
98 views

How to convert Expression<Func<TSource,TKey>> and TKey to Expression<Func<TSource,bool>>?

IQueryable.OrderBy receives a key selector expression Expression<Func<TSource,TKey>>. IQueryable.Single receives a comparison expression Expression<Func<TSource,bool>>. Can I ...
Kevin Krumwiede's user avatar
0 votes
0 answers
61 views

Debug info in expression tree

Is there a way to insert debug info into .NET expression tree, so that it's shown in the exception trace (e.g., source code location and custom function name). For example, given the code (that ...
Pero P's user avatar
  • 31
0 votes
1 answer
55 views

Why below function is not being optimized by using delegate?

I have below function to send the log. And I used to have a reflection approach.(The commented code inside the function). I would like to optimize the reflection, after some investigation online, I ...
wadefanyaoxia's user avatar
0 votes
1 answer
69 views

Linq Lambda Expression could not be translated

I have the following model public class Entity { public List<FirstLevel> FirstLevel { get; set; } } public class FirstLevel { public int ElementId { get; set; } } I am trying to fetch ...
A. Gorin's user avatar
1 vote
1 answer
166 views

EF Core 6: generic method to select distinct fields from the list

I need to write a generic method, which would return distinct values for two or more fields, given by the user in the List<string>. With some help, I have the below, which gives "Linq ...
Alex S.'s user avatar
  • 1,004
0 votes
0 answers
61 views

How to programmatically decompose an EF Core include clause

My EF Core application uses a design pattern that aims to support flexible entity queries, by allowing navigation property loading to be specified at runtime. There are 3 key elements to this pattern: ...
Tim Coulter's user avatar
  • 8,715
0 votes
0 answers
39 views

Get function information from expression tree

For documentary purposes, I want to automatically capture the functions called in my code and save them as a string to write down in my log. This works nicely if I just use plain lambdas, for example: ...
Thern's user avatar
  • 1,017
0 votes
0 answers
152 views

C# Writing dynamic query function using expression trees

Im trying to write a query function. And with expression trees I am trying to get runtime input to query. var query = context.Customers .Join(context.Orders, customer => ...
charthraxis's user avatar
-1 votes
1 answer
119 views

How to pass StartsWith() as a parameter to Expression.Call()?

Im trying to call StartsWith() function as an expression and pass a constant to it. var textConstant =Expression.Constant(text); var startsWith = Expression.Call(StartsWith ,textConstant); //something ...
charthraxis's user avatar
0 votes
1 answer
38 views

find maximum in arbitrary expression tree

I have a very simple language that gets compiled to an Expression tree, and then evaluated. Users can define mathematical operations, use variables and control flow. Moreover, from the script it's ...
apocalypsis's user avatar
0 votes
1 answer
81 views

Converting LINQ expression to expression tree queryable.Where(c => c.Tags != null && searchValues.All(s => c.Tags.Contains(s)));

I have a list of strings string[] searchValues and a LINQ expression queryable.Where(c => c.Tags != null && searchValues.All(s => c.Tags.Contains(s))); where .Tags is a List<string&...
Anarion's user avatar
  • 2,426
2 votes
0 answers
57 views

How could I generate a c# .NET core function that can mimic the Include().ThenInclude.(Where) behaviour?

I'm trying to create a generic blazor component that and has a config object. So far I've been able to successfully mimic .Where(), .Include().ThenInclude() separately, but now I need to add condition ...
J Pablo F's user avatar
0 votes
0 answers
82 views

Create a Lambda Expression having a WHERE IN Clause

I want to create a lambda expression dynamically for this: List<Coverage>? excludedCoverage = originalCoverage.Where(a => currentCoverage.Select(k => k.CoverageId).Contains(a.CoverageId) ==...
Michael's user avatar
  • 45
1 vote
1 answer
173 views

Filtering EF query based on filter object automatically

Let's say we have the following classes: class A { public int Id {get; set;} public string Name {get; set;} } class FilterA { public List<int> Ids {get; set;} public List<...
KorsaR's user avatar
  • 536
-1 votes
1 answer
149 views

Build EF core Where() predicate at runtime [closed]

I have written a piece of code which builds an EF Core Where() predicate at runtime. I have never done this before, but for the requirement I had to do it. The requirement is simply to get data from ...
thanzeel's user avatar
  • 451
1 vote
1 answer
160 views

Expression Property by string

I haven't worked with expressions that much, I am trying to reference an Expression property by string name but I cam getting this error: c# The member expression must specify a property or method ...
THE AMAZING's user avatar
  • 1,495
1 vote
3 answers
132 views

How to get the array length of an expression parameter

This method should return a function which can evaluate the scalar product of two vectors of the same size: public static Func<T[], T[], T> GetVectorMultiplyFunction<T>() where T : struct {...
kastrbl4nik's user avatar
0 votes
1 answer
76 views

Building GroupBy Expression Tree - IEnumerable parameter not defined error

I want to build an expression for IQueryable GroupBy. While at the moment I'm just simplifying the problem to try and get it working, the eventual final implementation will involve the creation of ...
PHyndman's user avatar
0 votes
1 answer
366 views

EF Core expression tree CONVERT

I'm having trouble writing EF Core expression tree code that would be able to translate to MS SQL Server query utilizing all 3 parameters of its built-in CONVERT function (CONVERT( type[(length)], ...
Goran Petrović's user avatar
0 votes
0 answers
131 views

EF Core expression tree FORMAT equivalent

I'm trying to build dynamic SQL queries using expression trees. I'm having issues implementing SQL Function FORMAT on datetime datatype. I would like to generate expression that would translate to the ...
Goran Petrović's user avatar
0 votes
1 answer
294 views

EF Core expression tree CAST equivalent

I'm trying to search for a string-equivalent value (which user inputs as HTTP request query parameter) in my SQL database on non-string columns (ie. bool, int, decimal, datetime, etc....). In order to ...
Goran Petrović's user avatar
0 votes
0 answers
111 views

What alternatives can be used to represent .NET's 'from-end' indexer expression inside a lambda/expression tree?

I wrote a mock for a test which tries to mimic a method involving any file uploaded with a ".jpg" extension and decided to use .NET's 'from-end' indexer expression for convenience in ...
terrible-coder's user avatar
0 votes
1 answer
146 views

Adding parent pointer to each node when creating binary expression tree

So I have a perfectly working binary expression tree, but when I tried to modify it to add a parent pointer to each node, (which I will later need to create a path from a node to the root), it doesn't ...
MikeHD's user avatar
  • 1
1 vote
1 answer
222 views

Project on update/create (set values from another object en masse) in LINQ2DB?

When using LINQ2DB for my application I tried to use entity-DTO mapping using Expression<Func<Entity, DTO>> and vice versa like described here: https://github.com/linq2db/linq2db/issues/...
Kerbiter's user avatar
0 votes
1 answer
119 views

Parsing Input Using Expression Tree

So I am trying to take a user input and then parse it into an expression that I have set up an expression tree for. The expression tree that I have is: data Expression = State [Float] Float ...
skiboy108's user avatar
0 votes
1 answer
107 views

LINQ Expression tree with Substring

I want to create SQL LINQ expression like: .Where(product => product.name.Substring(3,5).Contains("ma") Can someone help me to create that expression? Expression.PropertyOrField(body, &...
Esha Kheni's user avatar
1 vote
1 answer
96 views

Trying to add deriving(Show, Read) to an expression tree

I am fairly new to Haskell so it is probably something simple that I am missing but I have an expression tree that looks like this: data Expression = Lit Float | Add Expression ...
skiboy108's user avatar
1 vote
1 answer
55 views

Binary tree in-order python

I'm creating a binary tree and I'm stuck to convert it to postfix and infix. The problem is that I'm trying to create a method infix and postfix inside the class but it doesn’t work: TypeError: Node....
Adam's user avatar
  • 13
0 votes
1 answer
84 views

sympy: post order traversal over expression tree: skips top-level operation

I am trying to loop post order through a sympy-expression. It works fine except for the fact that it skips the last addition (im my example case the addition of sympy.sin(x * y) and z**2). import ...
user avatar
4 votes
1 answer
95 views

How does the C# compiler resolve types before applying a binary operator?

I'm working on a typed scripting language backed by C# Expression Trees. I'm stuck on one issue around proper type conversion with binary operators. Here is an example of the behavior I'm trying to ...
weichsem's user avatar
  • 278
0 votes
1 answer
109 views

How can I cast an object to string and use it in a Linq query using Reflection

There's the problem I made an Extension method to IQueryable and I want to get property name and value to do a select on it the thing is that I am using Expression tree and try to search rows by the ...
Ashkan Khalaj's user avatar
0 votes
0 answers
38 views

Why does my Expression Tree create a variable instead of setting the LabelTarget directly?

I have the "problem" with the following expression tree that it creates a local variable inside the "Try" instead of setting the value directly for the LabelTarget. It's not ...
CaptTaifun's user avatar
1 vote
2 answers
734 views

How to build where predicate in EF Core in which the property selected is dynamic

I'm struggling with expression trees and Entity Framework Core. I have a method that returns an expression tree that I will use for filtering, something like: public Expression<Func<E, bool>&...
Eric's user avatar
  • 1,945
0 votes
1 answer
306 views

C# Expression Trees and is null

I am trying to create an expression tree to make a lambda that can be used in an EntityFramework Where clause. I need to check for null and am trying to use is null. So something like this: var ...
LisaM's user avatar
  • 5
0 votes
1 answer
128 views

How to add a null-safe dereference operator and return null instead of executing the method

I write an assembly during runtime, which stores me all getter methods for all properties from about 1000 types. The code I use to pull the getters is as follows: public static void CreateGetter(...
CaptTaifun's user avatar

1
2 3 4 5
42