For example, let’s say i have a string property “Document.DocumentType.DocumentCode” with DocumentCode is a nullable decimal type.
How can I build an expression tree for this: x.Document.DocumentType.DocumentCode.GetValueOrDefault() == 4?
For my real case, I won’t know exactly what the linked string property will look like or the levels of properties.
Well, that tree is:
GetValueOrDefault()on (an expression)DocumentCodeon (an expression)DocumentTypeon (an expression)Documenton aParameterExpressionStart from the bottom, and build it up from there. In other words, if you know you’re only going to have properties, you’ll want to:
ParameterExpressionLoop round the set of properties, adding another layer or property access each time, e.g.
Add a method call at to the expression