608 questions
6
votes
1
answer
191
views
Difference between Expression.Return and Expression.Goto in C# Expression Trees
I'm experimenting with C# Expression Trees and trying to understand the difference between Expression.Return and Expression.Goto. I can’t create an example where Return and Goto behave differently ...
2
votes
1
answer
112
views
Implementing a LINQ Expression Visitor to Remove Pagination
I am trying to implement a LINQ Expression Visitor ([ExpressionVisitor][1]) for the following scenario: remove all pagination-related calls, such as Skip, Take, OrderBy, and OrderByDescending.
What I ...
0
votes
1
answer
59
views
Extract a strongly typed expression from a function expression body
I'm trying to write a "relaxed" comparison method which operates on Expressions and is used in Entity Framework. It consists of a chain of Replace() calls and ToLower() to perform an inexact ...
0
votes
1
answer
106
views
How to find entity types in IQueryExpressionInterceptor?
How can I find all the entity types referenced by the Expression passed to IQueryExpressionInterceptor.QueryCompilationStarting? Where in the expression tree should I look for them?
I've tried a ...
2
votes
2
answers
99
views
Dynamically created event handler that writes ito a `ref` parameter
I want to subscribe to any event existing on a given object, where I don't know the type in advance. I'm generatig event handler at run-time using System.Linq.Expressions.Expression.
The code I have (...
2
votes
2
answers
197
views
How can I reuse the logic in a .Include.Where() call while working with Entity Framework Core in .NET?
I am writing a database query using LINQ in .NET and I want to be able to not duplicate the code I put in my Where method calls.
I want to return Blogs that have fresh Comments, and want to filter ...
2
votes
1
answer
101
views
Compile deserialized Expression using Serialize.Linq
I'm not able to find the way how to compile the deserialized Expression using Serialize.Linq. The accepted answer in "Compile Expression at runtime Using Serialize.Linq" doesn't work (part 2 ...
0
votes
1
answer
58
views
Can I reuse one Expression object for multiple lambdas building?
I want to reuse Expression instances for another Expression building like in the code below. Is it safe? Are there any pitfalls with it?
using System.Linq.Expressions;
class Program
{
static void ...
2
votes
0
answers
61
views
EF6 generates WHERE clause in unexpected order
I'm using the solution from this answer to form an Expression<Func<Proposal, bool>> object (where Proposal is an entity type in my app), according to the searching criteria input on a ...
0
votes
0
answers
480
views
Parsing an OData filter string
I'm using radzen to build a filter and apply it to a view that acts as my data set. Most everything works fine however when I try to filter by DateTime I get an error
Conversion failed when ...
0
votes
2
answers
124
views
Convert Expressions C# with existing Queryable methods
I need to append methods to an existion experssion and combine them into a new resultExpression.
Expression<TSource, IQueryable<TResult>> sourceExpression;
Expression<TSource, int, int, ...
0
votes
3
answers
109
views
C# Linq Expression tree invalid cast exception going from int to double
I am trying to use C# object initializer syntax with LINQ Expressions trees and I used type conversions (i.e. Expression.Convert) so I shouldn't get invalid cast exceptions for simple type conversions ...
0
votes
1
answer
392
views
Expression Visitor to be used on other type
I'm trying to use an ExpressionVisitor to change a expression to be used on another underlying type.
Assume I have 2 class Foo and Bar, where Bar is a logical representation and Foo is a EF entity.
So ...
0
votes
1
answer
251
views
When can MemberExpression.Expression be null?
I wrote a simple utility method that accepts a lambda expression of the form x => x.PropertyName, and I want to validate that the expression is indeed of the correct form (the method then does ...
0
votes
0
answers
174
views
How to describe "return ref" in expression tree?
Func<T, TField> GetFunc<T, TField> (this FieldInfo fieldInfo) {
var instanceParameter = Expression.Parameter (typeof (T), "instance");
var fieldExpression = ...
0
votes
0
answers
49
views
Why does Expression.TryFault() always fail to Expression.Lambda<>().Compile() in netfx?
Given the following code:
using System;
using System.Linq.Expressions;
Console.WriteLine(Expression.Lambda<Func<string>>(Expression.TryFault(Expression.Constant("hi"), ...
0
votes
1
answer
519
views
Handling DateTimes with Linq Expression
I'm trying to create a Linq Expression to compare a date column with DateTime.Now
Here's my code
private void ProcessQueueEntries()
{
_logger.LogInformation("ProcessQueueEntries");
...
1
vote
0
answers
211
views
C# OrderBy used by Func Expression
Hi I am having problem with this expressions:
I am creating List of two expression for OrderBy(orderby(first from list).thenby(second from list)), but in some cases Recipient can be null.
List<...
0
votes
1
answer
344
views
Building Expression to search in child properies (collection) of object
I have a search setup to return matching Record objects based on criteria. It builds an Expression Tree based on the type of criteria and queries the database to return matches. Previously, it only ...
0
votes
1
answer
4k
views
Dynamic Linq in Entity Framework Core
I need to create a Linq query having Where and Select both dynamic.I am searching something like below code which will work in .net core.
var result = myQuery
.Where("Field1=\"SomeValue\&...
0
votes
1
answer
831
views
Build an expression tree that can handle any type/class with a "TryParse()" method
i have the following method that returns a "value parser" delegate according to the input type. it works fine but i'd like to get rid of the switch statements and type checks and be able to ...
3
votes
1
answer
1k
views
How to force SQL parameter instead of constant in Expression predicate
I want to create predicate expression so that it translates into WHERE clause with SQL parameter, e.g.:
WHERE e.Id = @id_1;
I have this code
int id = 1;
Expression<Func<Entity, int>> ...
1
vote
2
answers
2k
views
Set a property given a lambda expression for that property
I'm looking to create a slick helper function that compares two values, returns true if they are different, and also updates the first value to equal the second value. This is what I came up with:
...
0
votes
1
answer
952
views
Building a EF Compatible expression call using Any against any type
Related Articles:
How do I build Expression Call for Any Method with generic parameter
LINQ Expression Tree: Call Any method against a DbSet
I'd like to be able to dynamically construct a where ...
3
votes
0
answers
122
views
Is there a C# class that I can use to correctly convert the left or right Expressions of different types before using them in a BinaryExpression?
The Expression tree which results from C# Expression Expression<Func<int, decimal>> f = (int i) => i + 1.0m ; has the correct Expression.Convert applied to the integer parameter i ...