No, it wouldn't be better performance overall because you still have to "do" the database query in order to check whether there are any rows.
Also, exposing repository methods where you might further "chain" them sounds like a good idea at first (performance, composability, etc.). But it becomes harder to reason about when you are mixing and chaining multiple methods.
Ideally, you should have a repo method that does the one thing you need. If that involves having to do multiple SQL queries then that one method should do them. So performance isn't an issue (actually, it could be better in this scenario) and it's very explicit as to what your code is doing.
E.g. you might have a method called GetUsersForProductXHavingPendingOrders
You could make that into two methods: GetUsersForProductX and GetUsersHavingPendingOrders, but the one combined method is more explicit and under the covers can implement whatever performance "tricks" needed.
In the end, IQueryable is really only for LINQ-to-SQL providers to use.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
No, it wouldn't be better performance overall because you still have to "do" the database query in order to check whether there are any rows.
Also, exposing repository methods where you might further "chain" them sounds like a good idea at first (performance, composability, etc.). But it becomes harder to reason about when you are mixing and chaining multiple methods.
Ideally, you should have a repo method that does the one thing you need. If that involves having to do multiple SQL queries then that one method should do them. So performance isn't an issue (actually, it could be better in this scenario) and it's very explicit as to what your code is doing.
E.g. you might have a method called
GetUsersForProductXHavingPendingOrders
You could make that into two methods:
GetUsersForProductX
andGetUsersHavingPendingOrders
, but the one combined method is more explicit and under the covers can implement whatever performance "tricks" needed.In the end,
IQueryable
is really only for LINQ-to-SQL providers to use.