I have this method
public Expression<Func<Auction, bool>> GetUnsetDatesAuctionsExpression()
{
if (condition)
return GetAllUnsetDatesAuctionsExpression();
else
return (a =>
(membershipUser.ProviderUserKey != null) &&
(a.OwnerReference == (Guid)membershipUser.ProviderUserKey) &&
((a.Starts == null) || (a.Ends == null)));
}
}
which calls this method
private Expression<Func<Auction, bool>> GetAllUnsetDatesAuctionsExpression()
{
return (a => (a.Starts == null) || (a.Ends == null));
}
The issue is that in the above public method I have the below line
(a.Starts == null) || (a.Ends == null)
which is the same as the body of the expression in the private method.
Now, doing this, of course, does not work because you can’t AND a bool and an Expression
return (a =>
(membershipUser.ProviderUserKey != null) &&
(a.OwnerReference == (Guid)membershipUser.ProviderUserKey) &&
(GetAllUnsetDatesAuctionsExpression));
So, the question is, how do I combine the call to the private method with
(membershipUser.ProviderUserKey != null) &&
(a.OwnerReference == (Guid)membershipUser.ProviderUserKey)
Create a new expression as a combination of the two, see BinaryExpression: