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
100
views
Pass ModelExpression for use in asp-for tag helper in Razor Pages [duplicate]
I have some repeated code I'd like to move to a Razor Pages code block, which contains an asp-for tag helper. That expects a ModelExpression, and I'm unsure how to pass that.
@model IndexModel
@{
...
3
votes
2
answers
112
views
Why isn't my supplied predicate being matched when using Moq?
Given a simple type I'm testing, say
interface IMyRepo
{
MyObj GetBy(Expression<Func<MyObj, bool> predicate);
}
so the standard mock setup works just fine:
_repoMock.Setup(x => x.GetBy(...
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
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
0
answers
23
views
Strange ArgumentException in Expression Tree Query Statement
Note: the answer can be in either VB.NET or C#. I have no preference for this Q&A.
I'm trying to distill this rather cumbersome line:
Dim oSession As Session
oSession = Await Me.DbContext....
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
1
answer
100
views
How add MemberInitExpression into Bindings other Lambda MemberInitExpression
I have the following classes:
class Source {
public int Id { get; set; }
public string Name { get; set; }
public SourceItem Item { get; set; }
}
class SourceItem {
public Guid Id { ...
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
1
answer
161
views
Adding a dynamic GroupBy expression to an IQueryable
I want to pass a dynamic GroupBy expression into an IQueryable. I'm already doing something similar with a Where clause that is working OK.
The purpose of the group by is then to allow my to extract ...
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 ...
11
votes
1
answer
1k
views
Convert Linq expression "obj => obj.Prop" into "parent => parent.obj.Prop"
I have an existing expression of type Expression<Func<T, object>>; it contains values like cust => cust.Name.
I also have a parent class with a field of type T. I need a method that ...
0
votes
1
answer
524
views
Build expression tree with generic class for EF Core
I have a TPH architecture with the following hierarchy:
abstract class Task
{
public int A { get; set; }
}
abstract class DocumentTask
{
public virtual Document Doc { get;set; }
public int B ...
0
votes
1
answer
442
views
Combine 'Contains' with 'ToLower' in dynamic expression
I'm building a generic search using expressions, searching in all string properties of the model. However I'm having problems implementing 'Contains' alongside 'ToLower'.
Type elementType = typeof(...
2
votes
1
answer
239
views
Getting MethodInfo at compile time for a non-static method
I'm working on a program that calculates expressions at runtime based on a set of inputs, then executes those remotely. This requires creating expressions dynamically that call different helper ...
2
votes
1
answer
257
views
How to deconstruct expression tree to get value of captured variable
Consider the following block of code:
Expression<Func<string, bool>> pred;
{
string s = "test";
pred = x => x == s;
}
// how to retrieve the value of s from just pred?
...
4
votes
2
answers
333
views
Stateful Expression visitors multiple run issue
Let's say I need to write an expression visitor, which also uses some injectable service, hence it has to have a public constructor, and cannot be simply wrapped in a static facade.
public class ...
0
votes
0
answers
108
views
Enforce type of expression delegate at compile time
I want to make a method that takes a MemberExpression and does something with it. At the moment I can do
private string myfunction<T>(Expression<Func<T>> exp)
{
if (exp.Body is ...
3
votes
1
answer
1k
views
Converting Expression<Func<T,object>> to string
I try to convert an expression in the form Expression<Func<Person,object>> to a string for later manipulation.
This expression is stored in a property in a class and it's used in source ...
2
votes
2
answers
2k
views
SELECT result map to entity in Dynamic Linq in Entity Framework Core
I have a Linq query which is selecting 2 columns(that can be any 2 from all columns) dynamically based on some condition.I need to map the query result in to below model irrespective of selected ...
7
votes
4
answers
4k
views
Changing the return type of an expression<func<>>
Say I have an Expression<Func<T,object>> is it possible to dynamically change the return type based on a Type variable to be something like Expression<Func<T,int>>
I have the ...