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

In version 3.1.1, why string contains methods are case-sensitive #1128

Closed
hzicong opened this issue Jul 20, 2020 · 6 comments
Closed

In version 3.1.1, why string contains methods are case-sensitive #1128

hzicong opened this issue Jul 20, 2020 · 6 comments

Comments

@hzicong
Copy link

hzicong commented Jul 20, 2020

The issue

var query = _repository.GetAll().Where(p => p.Title.Contains(input.Title, StringComparison.CurrentCultureIgnoreCase))
or
var query = _repository.GetAll().Where(p => p.Title.Contains(input.Title)

Using the 2.2 with a lambda with a Where() and a Contains() filter generates the following SQL

SELECT `p`.`Id`, `p`.`CreationTime`, `p`.`EndTime`, `p`.`Icon`, `p`.`Intro`, `p`.`MobileAdvertBanner`, 
`p`.`MobileBanner`, `p`.`PCAdvertBanner`, `p`.`PCBanner`, `p`.`PriceIcon`, `p`.`ProductBuyCount`, 
`p`.`ProductCreationTime`, `p`.`SignUpEndTime`, `p`.`SignUpStartTime`, `p`.`StartTime`, `p`.`Title`
FROM `Product_Activity` AS `p`
WHERE (LOCATE(@__input_Title_0, `p`.`Mobile`) > 0) 
OR (@__input_Title_0 = ''))
ORDER BY `p`.`Id` DESC

The same query using the 3.1 provider generates the following SQL

SELECT `p`.`Id`, `p`.`CreationTime`, `p`.`EndTime`, `p`.`Icon`, `p`.`Intro`, `p`.`MobileAdvertBanner`, 
`p`.`MobileBanner`, `p`.`PCAdvertBanner`, `p`.`PCBanner`, `p`.`PriceIcon`, `p`.`ProductBuyCount`, 
`p`.`ProductCreationTime`, `p`.`SignUpEndTime`, `p`.`SignUpStartTime`, `p`.`StartTime`, `p`.`Title`
FROM `Product_Activity` AS `p`
WHERE ((LOCATE(CONVERT(LCASE(@__input_Title_0) USING utf8mb4) COLLATE utf8mb4_bin, LCASE(`p`.`Title`)) > 0) 
OR (@__input_Title_0 = ''))
ORDER BY `p`.`Id` DESC`

Further technical details

MySQL version: 5.7.22 or 8.0
Operating system: Win10 or Centos 8 docker
Pomelo.EntityFrameworkCore.MySql version: 3.1.1

@hzicong hzicong changed the title In Pomelo.EntityFrameworkCore.MySql 3.1.1 , why string contains methods are case-sensitive by default In Pomelo.EntityFrameworkCore.MySql 3.1.1 , why string contains methods are case-sensitive Jul 20, 2020
@mguinness mguinness changed the title In Pomelo.EntityFrameworkCore.MySql 3.1.1 , why string contains methods are case-sensitive In version 3.1.1, why string contains methods are case-sensitive Jul 20, 2020
@mguinness
Copy link
Collaborator

Likely duplicate of #996

@hzicong
Copy link
Author

hzicong commented Jul 21, 2020

should I change it to EF.Functions?

@lauxjpn
Copy link
Collaborator

lauxjpn commented Jul 21, 2020

As @mguinness said, we already fixed this for #996. It was a regression bug:

The provider is back to using the casing that is defined by the collation of the column (currently only nightly build, but will be part of 3.2.0).

If your collation for a given column is utf8mb4_0900_as_cs for example, the casing used (if no explicit StringComparison parameter is specified) is case sensitiv.

If on the other hand a utf8mb4_0900_ai_ci collation has been defined for the column, case _in_sensitive comparisons will be used.


Hopefully, this will be a 3.x release?

Yes, this will be part of the next Pomelo release, which will be 3.2.0.

The fix for this is part of our current nightly builds.


should I change it to EF.Functions?

If you don't want to use the nightly build, you can use EF.Functions.Like() as a workaround.

@hzicong
Copy link
Author

hzicong commented Jul 21, 2020

ok,thanks,which version i can use in 3.2.0-preview?

@lauxjpn
Copy link
Collaborator

lauxjpn commented Jul 21, 2020

It should show you the dependencies, when clicking on the package in your IDE before updating.
You can also take a look at the package in our nightly build feed:

Dependencies:

.NETStandard2.0
Microsoft.EntityFrameworkCore.Relational (≥ 3.1.3)
MySqlConnector (≥ 0.69.6 1.0.0)
Pomelo.JsonObject (≥ 2.2.1)

Also, the general versions are listed under Compatibility. Version 3.2.0 should be similar to 3.1.1.

@hzicong
Copy link
Author

hzicong commented Jul 22, 2020

Thanks

@hzicong hzicong closed this as completed Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants