Bug #60134 Entity Framework 4 - Support for "LIKE" function
Submitted: 15 Feb 2011 16:00 Modified: 21 Feb 2011 9:44
Reporter: Richard Deeming Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S4 (Feature request)
Version:6.3.6 OS:Microsoft 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.