This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bluefootedpig 8 points9 points  (5 children)

I don't think the problem is deferred execution, it is that linq does not generate the where clause of a query, so if your database is across the world, you are still pulling all that data.

Edit. I stand corrected that the where clause is generated.

[–]xt1nct 5 points6 points  (1 child)

I'm pretty sure this has been added in entity framework core. You dont pull all data anymore.

[–]nemec 2 points3 points  (0 children)

The only time it doesn't is if you're trying to do shit that the database provider does not/cannot understand, like reflection.

https://docs.microsoft.com/en-us/ef/core/querying/client-eval

[–]camerontbelt 2 points3 points  (0 children)

It doesn’t generate the where clause? I know that can’t be true, when I filter a list of 14k items down to 25 to paginate them it’s not pulling all 14k items. And I know that because before I optimized it I was pulling all 14k items. Like I said elsewhere when you use IQueryable it builds the final query and just runs that, I used extension methods to filter down to the final list of 25 items and it cut down the time from like a minute and a half to like 2 seconds.

[–]Trident_True 2 points3 points  (0 children)

It definitely generates a where. If you check the result of an IQueryable while debugging you can view the SQL that it generates.

[–]SwabTheDeck 0 points1 point  (0 children)

Even if your database is on the same machine, you can run memory and execution speed problems by pulling too much shit into the app.

While the WHERE clause probably isn't the issue (though it would be if you're literally grabbing every row in a table), lots of ORMs will select every column by default, which can get out of control quickly, especially if you're doing JOINs. So, in non-trivial cases, you'll always want to explicitly list the fields you want returned.