I am having a very strange issue on my application when deploying on a Windows 2008 R2 Server.
Given this very simple LINQ snippet:
return From
invoice In Me.Invoices
Where
loggedCustomerID.Contains(invoice.Contract.CustomerID)
Order By
invoice.Date Descending
The application works, but in some cases (on the customer server), the generated T-SQL is very strange:
SELECT
[Extent1].[ContractID] AS [ContractID], ...
FROM
[dbo].[Invoice] AS [Extent1]
INNER JOIN [dbo].[Contract] AS [Extent2] ON
[Extent1].[ContractID] = [Extent2].[ContractID]
LEFT OUTER JOIN [dbo].[Contract] AS [Extent3] ON
[Extent1].[ContractID] = [Extent3].[ContractID]
WHERE
[Extent2].[CustomerID] = 482283
OR [Extent3].[CustomerID] IN (498565,482282,498564,498566)
- Table is linked multiple times (?)
- The
IN
statement is broken into multiple T-SQL conditions instead of a singleIN
statement
Obviously the same package runs fine on my system generating the correct query without linking the same table multiple times and creating only a single IN
statement.
I am using EF 5.0 but with compatibility against the Framework 4.0 (so the assembly shows version 4.4). Is this the root cause of this issue?
What could be wrong here?
It looks like the behavior is related to this? Too Many Left Outer Joins in Entity Framework 4?