Expression in EF Core where clause takes too much time

101 views Asked by At

I would like to apply a filter to my SQL function results:

var data = await DbSet.FromSqlInterpolated($"SELECT * FROM [dbo].[MyFunc](...)")
                      .Where(x => x.Field == "some value")
                      .ToListAsync();

This will work. But if I define an expression

Expression<Func<Entity, bool>> filter = (x) => x.Field == "some value"

and apply it in the .Where clause, then execution will take 2 minutes instead of 2 seconds. In my logs, I can see that the SQL was generated correctly (no server side filtering), but it take 2 minutes to generate query.

Where is my mistake? Thanks.

0

There are 0 answers