-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Our translation of inline collections to SQL VALUES adds an explicit cast around the first element; this is to explicitly type it for cases where the literal's default type in the database wouldn't be the correct one (see #30605 about omitting that when we can):
SELECT ...
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT COUNT(*)
FROM (VALUES (CAST(2 AS int)), (999), (1000)) AS [v]([Value])
WHERE [v].[Value] > [p].[Id]) = 2However, when a collection parameter is translated to VALUES because of EF.Constant(), the VALUES is missing the explicit CAST() on the first element:
public virtual Task Parameter_collection_Where_with_EF_Constant_Where_Any()
{
var ids = new[] { 2, 999, 1000 };
return AssertQuery(
ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => EF.Constant(ids).Where(x => x > 0).Any()),
ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => ids.Where(x => x > 0).Any()));
}SQL:
SELECT ...
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE EXISTS (
SELECT 1
FROM (VALUES (2), (999), (1000)) AS [i]([Value])
WHERE [i].[Value] > 0)/cc @cincuranet