Since EF 3.5 doesn’t support collection parameters in the .Contain() method, I’ve seen numerous people suggest using custom expressions to work around this problem (http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0).
However, if I have a long list of IDs to filter out the generated SQL in this case contains an endless list of ORs. For example,
WHERE (99999 = [Extent1].[ID]) OR (99998 = [Extent1].[ID]) OR (99997 = [Extent1].[ID]) OR...
This generated SQL takes forever to execute on my computer but once I change the ORs to a “true” IN clause:
WHERE [Extent1].[ID] IN (99999,99998,99997...)
it completes in less than a second.
My question is what could I do to make LINQ generate a “true” IN clause instead of ORs?
The point of the workaround from MSDN is generation of OR sequence because LINQ provider in EFv1 doesn’t support IN operator and there is no way to generate it with LINQ.
If you want to use LINQ and not ESQL your only option is to upgrade to EFv4.