codecutout/StringToExpression

How to filter nested List

Opened this issue · 2 comments

Hello,

I have a question, how can you filter by a property in a nested list? For example:

public class Receipt
{
       public Guid Id {get;set;}
       public string ReceiptNo {get;set;}
       public List<ReceiptPositon> Positions {get;set;}
}

public class ReceiptPosition
{
     public Guid ReceiptId {get;set;}
     public int ProductCount {get;set;}
}

Now I want to find all Receipts where a Positions has a ProductCount greater than 2. I tried doing something like this:

$filter=Positions/ProductCount gt 2

With debugging I found out that this doesn't work because Positions is a List and a List doesn't have the property ProductCount. How would the correct Syntax be?

During some downtime I tried myself to implement the feature. If someone is interestet to check it out: d36468a
This is my first time contributing to something on Github, so you have to do some controlling yourself if everything is correct.

Im impressed that you got collection predicates to work! I had made a first attempt at it but realized it was trickier than I first thought and never managed to find time to go back to it

A few comments based on the commit

  • Ideally everything related to the specifics of the odata would be contained in the odata language, any/all functions should be defined in the language not the basic grammer
  • Im of mixed opinion on the Accessor. Change to that would be a major version bump (contract change), and I generally try to avoid implicit operators (ive found they are not well understood by most dotnet devs, and they cause very difficult to diagnose bugs if the operator results in exceptions). However I have to admit that it solves the nested parsing issues in a very concise way
  • appreciate the dotnet version bump as versions have moved on since original development, but at least keep a netstandard2.0 on there so it can work in netcore apps

If you raise the change as a pull request I can comment more directly on the code and get it in a release