Query: Contains method on client list of nullable guid/int fails to translate to server #7922
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Milestone
When a nullable Guid and a non-nullable Guid are compared using the Contains() method I get a log message: "could not be translated and will be evaluated locally". Unfortunately this is then downloading a big table to perform the comparison causing a performance problem. This occurs whether the nullable is an argument to or the caller of .Contains() as will be shown in the four cases below.
This may be related to #7616
Steps to reproduce
Here is a cut-down version of the entity:
Here are the four cases with resulting log messages and MySQL
SELECT
s
.SkillId
,s
.Name
,s
.PrimarySkillId
,s
.Source
,s
.SourceId
FROM
Skills
ASs
WHERE
s
.PrimarySkillId
IN (...)The LINQ expression '{__primarySkills_0 => Contains(Convert([s].SkillId))}' could not be translated and will be evaluated locally.
The LINQ expression 'Contains(Convert([s].SkillId))' could not be translated and will be evaluated locally.
SELECT
s
.SkillId
,s
.Name
,s
.PrimarySkillId
,s
.Source
,s
.SourceId
FROM
Skills
ASs
and the inverse is true:
SELECT
s
.SkillId
,s
.Name
,s
.PrimarySkillId
,s
.Source
,s
.SourceId
FROM
Skills
ASs
WHERE
s
.SkillId
IN (...)The LINQ expression '{__primarySkills_0 => Contains(Convert([s].PrimarySkillId))}' could not be translated and will be evaluated locally.
The LINQ expression 'Contains(Convert([s].PrimarySkillId))' could not be translated and will be evaluated locally.
SELECT
s
.SkillId
,s
.Name
,s
.PrimarySkillId
,s
.Source
,s
.SourceId
FROM
Skills
ASs
WHERE
s
.PrimarySkillId
IS NOT NULLUnfortunately what I need to do is compare to both fields at once - so I can't get away from the nullable problem so easily. Ideally what I want is:
Further technical details
These are my relevant project references:
PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1"
PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1"
PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final"
PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.0-"
PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.0-"
Workaround
Having written all this up I realised a stupidly simple workaround, and this works fine, but I'm thinking this is still something that'd be useful for you to know about.
SELECT
s
.SkillId
,s
.Name
,s
.PrimarySkillId
,s
.Source
,s
.SourceId
FROM
Skills
ASs
WHERE
s
.SkillId
IN (...) ORs
.PrimarySkillId
IN (...)The text was updated successfully, but these errors were encountered: