I'm trying to build a parser of expressions to Odata, and i'm getting an error, when the field is nullable.
public class UserRight
{
public bool? active
}
public void Test(){
Expression<Func<UserRight, bool>> expression = p => p.Active == true;
}
It generates me the following expression:
{p => (p.Active == Convert(True, Nullable`1))}
But I'd like to receive it as
{p => (p.Active == True)}
In order to avoid this "Convert". Is there an easy way to do that? Because my parser is ready, and I would not like to rebuild it just because of a nullable field.
p => p.Active == true
is actuallyp => p.Active == (bool?)true
. And the cast in expression trees is represented byConvert
expression. So you cannot avoid it. – Shellieshellproof{p => (p.active == Convert(True))}
, "?? false" generates me{p => (p.active ?? False)}
and ".Value" generates{p => (p.active.Value == True)}
– Lasky