Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute with a lambda throw exception #1103

Closed
vabic opened this issue Nov 24, 2023 · 1 comment · Fixed by #1115
Closed

Compute with a lambda throw exception #1103

vabic opened this issue Nov 24, 2023 · 1 comment · Fixed by #1115
Assignees
Labels
bug Something isn't working

Comments

@vabic
Copy link

vabic commented Nov 24, 2023

Assemblies affected
tried on 8.0.6 and 8.2.3

Describe the bug
Here is the repo with the problem described below: https://github.com/vabic/ODataComputeLambdaErrorExample.git
This example is based on Sam Xu blog $compute and $search in ASP.NET Core OData 8 here with the starter repo NewQueryOptionIn8 also tagged in your README. So I took it as an official example.
I added a new prop on the Product model IList Candys like this:
public IList<string> Candys { get; set; }

                new Product
                {
                    Id = 3, Name = "Noodle", Color = Color.Brown, Price = 2.99, Qty = 50, Category = Category.Food, TaxRate = 0.10,
                    Location = addresses[1],
                    Sales = new List<Sale>
                    {
                        new Sale { SaleDate = new Date(1999, 8, 12), ProductId = 3, Amount = 11 },
                        new Sale { SaleDate = new Date(2018, 3, 19), ProductId = 3, Amount = 8 },
                    },
                     **Candys = new List<string>(){ "kit kat"}**
                },
                new Product
                {
                    Id = 4, Name = "Flute", Color = Color.Yellow, Price = 12.0, Qty = 75, Category = Category.Music, TaxRate = 0.14 ,
                    Location = addresses[0],
                    Sales = new List<Sale>
                    {
                        new Sale { SaleDate = new Date(2022, 12, 9), ProductId = 4, Amount = 15 },
                        new Sale { SaleDate = new Date(2022, 5, 29), ProductId = 4, Amount = 18 },
                    },
                     **Candys = new List<string>(){ "candy"}**
                },
                new Product
                {
                    Id = 5, Name = "Paper", Color = Color.White, Price = 6.99, Qty = 14 , Category = Category.Office, TaxRate = 0.24,
                    Location = addresses[2],
                    Sales = new List<Sale>
                    {
                        new Sale { SaleDate = new Date(2013, 1, 9), ProductId = 5, Amount = 2 },
                        new Sale { SaleDate = new Date(2022, 1, 1), ProductId = 5, Amount = 3 },
                    },
                     **Candys = new List<string>(){ "Snikers"}**
                },

I try to do a $compute on a Candy prop with a lambda expression to compute who has Snikers and I get an error :
OData Url: http://localhost:5102/odata/products?$select=HasSnikers&$compute=Candys/any(r:r eq 'Snikers') as HasSnikers
Error: "The query specified in the URI is not valid. The binary operator Equal is not defined for the types 'NewQueryOptionIn8.Models.Product' and 'System.String'.",

Reproduce steps
clone repo, start the solution, use Postman or equivalent.

Screenshots
image

@vabic vabic added the bug Something isn't working label Nov 24, 2023
xuzhg added a commit that referenced this issue Nov 29, 2023
@xuzhg
Copy link
Member

xuzhg commented Nov 29, 2023

@vabic Would you please help review the PR?

xuzhg added a commit that referenced this issue Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants