我有一个带有两个导航属性的Tasks表 - VersionReported和VersionResolved,它们都存储在表版本中。当我尝试使用包含这两个属性的任务列表时,我在SQL中获得了太多的连接(这只是来自探查器的sql的一部分):
LEFT OUTER JOIN [dbo].[Versions] AS [Extent4] ON [Extent1].[IDVersionReported] = [Extent4].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent5] ON [Extent1].[IDVersionReported] = [Extent5].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent6] ON [Extent1].[IDVersionReported] = [Extent6].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent7] ON [Extent1].[IDVersionReported] = [Extent7].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent8] ON [Extent1].[IDVersionResolved] = [Extent8].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent9] ON [Extent1].[IDVersionResolved] = [Extent9].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent10] ON [Extent1].[IDVersionResolved] = [Extent10].[ID]
LEFT OUTER JOIN [dbo].[Versions] AS [Extent11] ON [Extent1].[IDVersionResolved] = [Extent11].[ID]
Extent1是Tasks表。我知道当两个或多个导航属性导致同一个表时,EntityFramework有问题,但有没有人找到解决方案?
答案 0 :(得分:2)
我在大约2个月前加入了EF项目,我们也发现了这个问题。
我想最简单(也是表现最佳)的解决方案是创建一个视图来执行所有JOIN魔术,并在EF中映射该视图。
另一方面,在我们开始使用EF时,需要查看每个性能问题的视图可能不是我们所期望的。