2

我有一个这样的查询:

context.Diffusions.Where(x => x.ProgrammeId == programmeID).Include("Chaines").Include("Version").ToList();

生成的查询是:

SELECT 
[Extent1].[Duree] AS [Duree], 
[Extent1].[Id] AS [Id], 
[Extent1].[ProgrammeId] AS [ProgrammeId], 
[Extent1].[VersionId] AS [VersionId], 
[Extent1].[ChaineId] AS [ChaineId], 
[Extent1].[Debut] AS [Debut], 
[Extent1].[Fin] AS [Fin], 
[Extent1].[ReRun] AS [ReRun], 
[Extent1].[DateModification] AS [DateModification], 
[Extent1].[DateDiffusion] AS [DateDiffusion], 
[Extent2].[Id] AS [Id1], 
[Extent2].[Nom] AS [Nom], 
[Extent2].[Code] AS [Code], 
[Extent2].[Abreviation] AS [Abreviation], 
[Extent3].[Id] AS [Id2], 
[Extent3].[ProgrammeId] AS [ProgrammeId1], 
[Extent3].[CleVersion] AS [CleVersion], 
[Extent3].[Numero] AS [Numero], 
[Extent3].[NumeroModification] AS [NumeroModification], 
[Extent3].[VO] AS [VO], 
[Extent3].[TitrePresse] AS [TitrePresse], 
[Extent3].[Description] AS [Description], 
[Extent3].[Remarque] AS [Remarque], 
[Extent3].[SousTitre] AS [SousTitre], 
[Extent3].[DureeTheorique] AS [DureeTheorique], 
[Extent3].[Format] AS [Format], 
[Extent3].[Interdit] AS [Interdit], 
[Extent3].[LangueId] AS [LangueId], 
[Extent3].[TypeCoteDiffusionId] AS [TypeCoteDiffusionId]
FROM   [dbo].[Diffusion] AS [Extent1]
INNER JOIN [dbo].[Chaine] AS [Extent2] ON [Extent1].[ChaineId] = [Extent2].[Id]
INNER JOIN [dbo].[Version] AS [Extent3] ON [Extent1].[VersionId] = [Extent3].[Id]
WHERE [Extent1].[ProgrammeId] = 1926475

我的问题是表格有很多条目,它为每个条目进行内部连接,然后执行“WHERE”,因此需要 6 秒。

当我在没有包含的情况下进行查询时,它是即时的。我想要一个 linq 查询来执行“WHERE”,然后为返回的每一行执行“INCLUDE”,而不必为每个条目手动执行(一个程序可以有 1 000 个扩散)。

4

1 回答 1

0

试试这个代码并使用包含例如下面的代码

 context.Diffusions.Where(x => x.ProgrammeId == programmeID).Contains("Chaines").Include("Version").ToList();
于 2013-11-02T05:28:29.560 回答