question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OData contains does not generate the correct sql

See original GitHub issue

In 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

ODataTestProject.zip

  1. Run the sql file inside the zip to seed data.
  2. Alter the settings.
  3. Run the project.
  4. 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Sep 29, 2021

Well, preparing fix. Generated SQL is:

--  MySql.Official MySql
DECLARE @TypedProperty_1 VarChar(3) -- String
SET     @TypedProperty_1 = '%2%'

SELECT
	`$it`.`Id`,
	`$it`.`Name`
FROM
	`Students` `$it`
WHERE
	`$it`.`Name` LIKE @TypedProperty_1 ESCAPE '~'
1reaction
sdanylivcommented, Apr 26, 2021

Thanks for reporting. Looks like a bug.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found