AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Adds support for the $this literal #171

Closed wbuck closed 1 year ago

wbuck commented 1 year ago

This addresses request: #169

BlaiseD commented 1 year ago

Seems to me we just need something like the following:

        private const string DollarIt = "$it";
        private const string DollarThis = "$this";

and

        private IExpressionPart GetNonResourceRangeVariableReferenceNodeFilterPart(NonResourceRangeVariableReferenceNode nonResourceRangeVariableReferenceNode)
            => new ParameterOperator
            (
                parameters,
                ReplaceDollarThisParameterName(nonResourceRangeVariableReferenceNode.RangeVariable.Name)
            );

        private IExpressionPart GetResourceRangeVariableReferenceNodeFilterPart(ResourceRangeVariableReferenceNode resourceRangeVariableReferenceNode)
            => new ParameterOperator
            (
                parameters,
                ReplaceDollarThisParameterName(resourceRangeVariableReferenceNode.RangeVariable.Name)
            );

        private static string ReplaceDollarThisParameterName(string rangeVariableName) => rangeVariableName == DollarThis ? DollarIt : rangeVariableName;
wbuck commented 1 year ago

Yeah, I think originally when I wrote this my thought process was to allow queries like this:

$it => $it.SomeValueCollection.Any($this => $this gt $it.MyValue)

Or using $root potentially`. Now in those cases there is nothing setup to create capturing lambda's so the above query wouldn't work.

I'll simplify the code.

@BlaiseD Done

BlaiseD commented 1 year ago

Made some minor changes - better to leave a public method in until a major version release.

BlaiseD commented 1 year ago

Thanks