OData contains does not generate the correct sql
See original GitHub issueIn this example the following query gets generated:
DECLARE @TypedProperty_1 VarChar(3) -- String
SET @TypedProperty_1 = '%2%'
SELECT
`$it`.`Id`,
`$it`.`Name`
FROM
`test_db`.`Students` `$it`
WHERE
CASE
WHEN `$it`.`Name` IS NULL THEN NULL
ELSE `$it`.`Name` LIKE @TypedProperty_1 ESCAPE '~'
END = 1
Though it should have generated this query (EF Core generated):
DECLARE @TypedProperty_1 VarChar(3) -- String
SET @TypedProperty_1 = '%2%'
SELECT
`$it`.`Id`,
`$it`.`Name`
FROM
`test_db`.`Students` `$it`
WHERE
(@__TypedProperty_0 LIKE '') OR (LOCATE(@__TypedProperty_0, `a`.`Name`) > 0)
Additionally, when using the EFCoreTools library, it generates this query:
DECLARE @TypedProperty_1 VarChar(3) -- String
SET @TypedProperty_1 = '%2%'
SELECT
`$it`.`Id`,
`$it`.`Name`
FROM
`test_db`.`Students` `$it`
WHERE
CASE
WHEN `$it`.`Name` IS NULL
THEN NULL
ELSE NULL
END = 1
Steps to reproduce
- Run the sql file inside the zip to seed data.
- Alter the settings.
- Run the project.
- Navigate to: https://localhost:5001/api/values?$filter=contains(Name,‘2’)
Environment details
linq2db version: 3.3.0 Database Server: MySql 8.0.21 Database Provider: linq2db.MySql v3.3.0 Operating system: Windows 10 .NET Framework: .NET 5
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Why does my OData v4 API work for ?$filter=contains, but ...
I've written some OData V4 APIs to pull data from a local SQL database. I'm using curl to query the API. The APIs...
Read more >Solved: Filter OData query with not contains
Solved: Hi, I would like to filter my 'Get Items' function with a "Does not contain" type of filter but I am unsure...
Read more >Basic Tutorial · OData - the Best Way to REST
OData, short for Open Data Protocol, is an open protocol to allow the creation and consumption of queryable and interoperable RESTful APIs in...
Read more >How to properly use OData filters in Power Automate
You can use the table below to help with common OData filter operators. The first option 'eq' was used in the examples in...
Read more >OData Query Options
1 Introduction This is a list of query options for OData. We currently only support the options described here. 2 Retrieving Objects 2.1 ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, preparing fix. Generated SQL is:
Thanks for reporting. Looks like a bug.