Bug #60134 Entity Framework 4 - Support for "LIKE" function
Submitted: 15 Feb 2011 16:00 Modified: 10 Aug 2022 17:14
Reporter: Richard Deeming Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / NET Severity:S4 (Feature request)
Version:6.3.6 OS:Windows
Assigned to: CPU Architecture:Any

[15 Feb 2011 16:00] Richard Deeming
Description:
Entity Framework 4 added support for translating the "StartsWith", "EndsWith" and "Contains" methods on the string class to queries which use the "LIKE" function.

To support this new feature, the MySqlProviderManifest class needs to override the new SupportsEscapingLikeArgument method. 

Connector/Net v3.6.3 doesn't override this method, so these methods are translated to use the "LOCATE" function instead.

How to repeat:
Create an entity data model for a database, and issue a query which uses StartsWith. For example:

var query = from contact in context.Contacts
            where contact.Surname.StartsWith("L")
            select new
            {
                contact.ContactId,
                contact.Surname
            };

Expected query:
---------------
SELECT
    1 AS `C1`,
    `Extent1`.`ContactId`,
    `Extent1`.`Surname`
FROM
    `Contacts` AS `Extent1`
WHERE
    `Extent1`.`Surname` LIKE @gp1 ESCAPE '~'

Actual query:
-------------
SELECT
    1 AS `C1`,
    `Extent1`.`ContactId`,
    `Extent1`.`Surname`
FROM
    `Contacts` AS `Extent1`
WHERE
    LOCATE(@gp1, `Extent1`.`Surname`) = 1

Suggested fix:
Add the following to the .NET 4 version of the MySqlProviderManifest class:

public override bool SupportsEscapingLikeArgument(out char escapeCharacter)
{
    escapeCharacter = '~';
    return true;
}
[21 Feb 2011 9:44] Valeriy Kravchuk
Thank you for the feature request.
[10 Aug 2022 17:14] Daniel Valdez
This is an old bug. We no longer support EF4 and this feature has been
implemented with EF6. Closing as rejected. User should use the latest EF.