This is what I've fund out. Maybe it will help to someone:
So here we go:
If You use LINQ with EF looking for some exact elements contained in the list like this:
await context.MyObject1.Include("MyObject2").Where(t => IdList.Contains(t.MyObjectId)).ToListAsync();
everything is going fine until IdList contains more than one Id.
The “timeout” problem comes out if the list contains just one Id. To resolve the issue use if condition to check number of ids in IdList.
Example:
if (IdList.Count == 1)
{
result = await entities. MyObject1.Include("MyObject2").Where(t => IdList.FirstOrDefault()==t. MyObjectId).ToListAsync();
}
else
{
result = await entities. MyObject1.Include("MyObject2").Where(t => IdList.Contains(t. MyObjectId)).ToListAsync();
}
Explanation:
Simply try to use Sql Profiler and check the Select statement generated by Entity frameeork. …