I have a class
class MyClass
{
string Foo { get; set; }
int Bar { get; set; }
//... Other properties
}
Now what I have is two expressions
Expression<Func<MyClass, string>> expr1 = x => x.Foo;
Expression<Func<MyClass, bool>> expr2 = x => x.Bar > 0;
Using this two expressions, I want to create an expression which is something like this
Expression<Func<MyClass, object>> expr = x => new { Foo = x.Foo, Baz = x.Bar > 0 };
In other words I want to combine two properties into one anonymous object using expression trees. My problem is, How do I create a similar expression from the given two expressions?
I want to use final expression in a join statement with entity framework query. The bool part is complex and need to generate dynamically. If any alternative idea to this, that would be helpful too.