InvalidCastException PropertyExpression -> LambdaExpression
I am using the following code:
public static Func<T1, bool> StatusOffen
{
get { return d => d.status < 400; }
}
public void Test()
{
Expression<Func<T1, bool>> expr1 = a => Item.StatusOffen(a);
Expression<Func<T1, bool>> expr2 = a => Item.StatusBearbeitbar(a);
Expression<Func<T1, bool>> expr3 = a => Item.StatusKeinVersand(a);
var predicate = PredicateBuilder.False<T1>();
predicate = predicate.Or(expr1);
predicate = predicate.Or(expr2);
predicate = predicate.Or(expr3);
////predicate = predicate.Or(a => a.status < 400);
////predicate = predicate.Or(a => a.status == 850);
////predicate = predicate.Or(a => a.status == 400);
IQueryable<T1> query1 = this.GetByFilterObjectInternal(entities);
query1 = query1.AsExpandable().Where(predicate);
....
}
On calling the where statement I get the invalid cast Exception. If I use the commented variant instead all runs well. So what should I do to use the funcs? Best regards freica
this already has a solution in here
but I don't know why still it's not fixed in the source code. @scottksmith95 @StefH is there any special reason the method and property expressions support still it's not added to the source?
I actually forked this repo to apply fix from that SO thread only to find that it's actually already fixed and works fine. It doesn't work in OPs scenario because the property invoked should return Expression<Func<...>>, not just Func<...>.
I encountered the same issue. Has anyone actually filled a pull request to fix this? I'll look around if the issue is actually identical and will file a PR to close this issue.
Seems I cannot reproduce my issue which resembles the provided code.. but with Expression<Func<..>> instead of simply Func<>. I'll need to take a fresh look at my code to properly find out I did something stupid.