Multiple SQL connections created with Entity Framework
I have a Tasks table with two navigation properties - VersionReported and VersionResolved, which are stored in the Versions table. When I try to get a list of tasks with both properties enabled, I get too many joins in SQL (this is only the sql part from the profiler):
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 is a task table. I know EntityFramework has problems where two or more navigation properties result in the same table, but has anyone found a solution?
+2
source to share
1 answer
I joined the EF project about 2 months ago and we noticed this issue too.
I think the simplest (and most efficient) solution is to create a view that does all the JOIN magic and render that view in EF.
On the other hand, requiring a look at every performance issue is probably not what we expected when we started with EF.
+2
source to share