608 questions
6
votes
2
answers
1k
views
Linq.Expression TryCatch - Pass exception to Catch Block?
So I've been tinkering with Linq.Expressions (and if anyone can suggest a more proper or more elegant way to do what I'm doing please feel free to chime in) and have hit a wall in trying to do ...
0
votes
4
answers
1k
views
Building a LINQ lambda expression that can output enums, decimals, and strings
I am writing a re-usable view for my app. It uses a generic ViewModel DynSingleView<T>; you plug in the object type and the view will generate the property UI components to update them. It gets ...
1
vote
0
answers
369
views
how to convert LambdaExpression.Body to Expression<Func<...>> without generic
This is very similar to this answer however, I don't have type information at build time. I have Type variable. How would I cast LambdaExpression to Expression<Func<T,bool>> where T is ...
1
vote
1
answer
206
views
How can I combine (n) expressions using LINQ?
I have a grid with (n) dynamically generated columns. One of the requirements is that a row only be shown in the grid if a non-null/non-zero value exists in one of the shown columns. I am using an ...
1
vote
2
answers
389
views
How to apply generic expression-trees code that works well on integers, to enums (e.g. how to make Expression.PostIncrementAssign() work on enums?)?
I'm trying to create an extension method to do this:
enum AlphaBet { A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z }
IEnumerable<AlphaBet> rangeCtoG = AlphaBet.C.RangeToInc(AlphaBet.G);
...
2
votes
1
answer
60
views
Why does a variable value have to be modelled as a member access to the closure in an expression tree?
When I write expressions in our application as lambda expressions, I can usually make use of the following construct1:
dbContext.Contents<MyEntity>()
(dbContext is of a custom class.)
Somehow, ...
0
votes
1
answer
435
views
Linq Dynamic query and include non related entity
I have a scenario where I have 3 Entities
class entityA
{
public Guid Id { get; set; }
public string NameA { get; set; }
}
class entityB
{
public Guid Id { get; set; }
public string ...
5
votes
1
answer
998
views
How to create `ExpressionType.IsTrue/IsFalse`?
TL;DR
How do you create an Expression where
Expression.NodeType == ExpresionType.IsTrue || ExpresionType.IsFalse
Background Info
I am creating a custom version of EnumerableQuery, where I rewrite ...
3
votes
1
answer
3k
views
How can I find out if an Expression is writeable?
Based on some user input, I dynamically compose an Expression. Now, I need to distinguish the case where this expression is writable from the case where it's not. An example of a writable expression ...
2
votes
0
answers
191
views
Is it possible to downcast a variable in an expression tree to a known generic derivation closed by Expression.Parameter(typeof(Type))?
I have an Expression.Call which uses Expression.Parameter(typeof(Type)) to return an instance of type SomeType, which is in fact a derived class SomeType<T> with a field SomeField of type T ...
1
vote
1
answer
173
views
How can I get Property Expression for field of a property
I'm using Entity Framework 6. I have 2 classes:
public class BookingRecord
{
public int Id {get; set;}
public int CustomerId {get; set;}
[ForeignKey("CustomerId")]
public virtual ...
0
votes
1
answer
154
views
How to pass Func to a class which encapsulates the Expression based on that Func?
I have class DropdownFilter which has:
private readonly Func<TEntity, string> fieldWhichMustEqualValue;
public override IQueryable<TEntity> Filter(IQueryable<TEntity> ...
2
votes
1
answer
155
views
Boxed Values Using Linq to Entities
This is a follow up to my question Dynamic Expression Generation Issues with ValueTypes adding in a new variable: Entity Framework. Now that I am able to generate the necessary Expressions when ...
0
votes
1
answer
316
views
c# reusable property to be called passed by lambda
I'm trying to write a method that would take an object with property name as a lambda parameter, and use it on passed object, but also use it on another, new object of the same type created inside ...
-1
votes
2
answers
252
views
how to set value in List with out using foreach loop
I am having two lists and filter based on a group of values.
var UserIdList = response.Users.Select(p => p.Id).ToList();
var filteredRecords =
(from o in om.Organizations join u in om.Users on ...
1
vote
1
answer
2k
views
Linq Expressions. Equivalent of greater than for strings
I have followed several threads on SO and other websites and am still having difficulty.
I have the following code:
public static IQueryable<TSource> Between<TSource, TKey>(this ...
8
votes
0
answers
451
views
Expression.Call() overload for calling an instance method expecting a single argument is missing. Is there a reason for this?
Looking at the documented overloads available for the Expression.Call(), method, I can find the following overloads to obtain an expression node that will perform a call to an instance method ...
3
votes
1
answer
2k
views
Join/chain two expressions [duplicate]
How can I combine/join/chain two Expressions into one?
E.g
Expression<Func<A,object>> first = x => x.B.C;
Expression<Func<C,object>> second = x => x.D.E;
Where the end ...
2
votes
0
answers
1k
views
Combining multiple expressions to dynamically create select expression containing expressions as getters
Given an input of two expressions, e.g.:
Expression<Func<Customer,string>> nameExpression = x=>x.Name;
Expression<Func<Customer,string>> nameExpression = x=>x....
0
votes
2
answers
2k
views
Convert Expression<Func<T, object>> to Expression<Func<object>>
How to convert : Expression<Func<T, object>> to Expression<Func<object>>?
For example:
public class Entity
{
public virtual long Id { get; set; }
}
Origin:
...
-1
votes
1
answer
111
views
De/Serialize basic Linq Expressions using BinarySerializer
I'm looking for a library/tool in order to be able to de/serialize Linq Expressions.
Is there some library over there?
Is already suported natively on .Net? How could I get an starter stuff code?
4
votes
0
answers
51
views
Composing Expressions that return object instances in an Entity Framework friendly way [duplicate]
Suppose I have two classes that look like this:
public class Foo
{
public ICollection<Bar> Bars { get; set; }
public static Expression<Func<Foo, Bar>> GetNewestBar()
{
...
0
votes
1
answer
56
views
Dictionary of sub-class related linq expressions
Consider the following code example, modelling base and sub-classes:
class Entity
{
}
class Dough : Entity
{
}
class Bread : Entity
{
IEnumerable<Dough> TypesOfDough { get; set; }
}
...
0
votes
1
answer
191
views
Linq Expression Trees and Filtering Logic
I am new to Linq Expressions.
I am calling an API, that exposes the following overloaded methods:
CustomPaging<TEntity> GetAll(int index, int maxPage, Expression<Func<TEntity, int>&...
3
votes
1
answer
3k
views
Expression Tree for o?.Value
I'd like to generate this sentence using Expression trees:
o?.Value
o is an instance of whichever class.
Is there some way?