3

尽管我们尽了最大的努力,但在 where 语句中使用 contains 时,我们仍然无法让 Entity Framework (6.1.3) + Oracle Managed Data Access (12.1.2400) 生成“IN”子句。

对于以下查询:

var x = Tests
.Where(t => new[] { 1, 2, 3}.Contains(t.ServiceLegId));

var query = x.ToString();

使用 MS SQL (SQL Server) 我们看到生成了以下内容:

SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[TestRunId] AS [TestRunId], 
[Extent1].[DidPass] AS [DidPass], 
[Extent1].[StartTime] AS [StartTime], 
[Extent1].[EndTime] AS [EndTime], 
[Extent1].[ResultData] AS [ResultData], 
[Extent1].[ServiceLegId] AS [ServiceLegId]
FROM [dbo].[Test] AS [Extent1]
WHERE [Extent1].[ServiceLegId] IN (1, 2, 3)

使用 Oracle,我们看到:

SELECT 
"Extent1"."Id" AS "Id", 
"Extent1"."TestRunId" AS "TestRunId", 
"Extent1"."DidPass" AS "DidPass", 
"Extent1"."StartTime" AS "StartTime", 
"Extent1"."EndTime" AS "EndTime", 
"Extent1"."ResultData" AS "ResultData", 
"Extent1"."ServiceLegId" AS "ServiceLegId"
FROM "dbo"."Test" AS "Extent1"
WHERE ((1 = "Extent1"."ServiceLegId") OR (2 = "Extent1"."ServiceLegId") OR (3 = "Extent1"."ServiceLegId"))

这是我们实际必须做的一个简单的例子。在实际代码库中,此列表可能会变得很长,因此一系列“或”语句会导致执行计划非常低效。

有没有人遇到过这种情况?我觉得我们已经尝试了一切......

4

0 回答 0