I have created a WCF data service over a fairly simple EF 4.1 code first model. With each request I must provide a clientid to maintain segregation of data in my multi-tenant db. I am seeing horrible performance and after running a sql server trace I see that all of the parametrized queries are using subqueries like so.
select top 100 <This is because of paging>
colA,
colB,
colC
from (select colA, colB, colC
from table
where clientid = 12345)
orderby .....
Is there any way to tweak this so that it skips the subquery for the select? It seems ridiculously unneeded and slows down the performance by a surprising order of magnitude.
Thanks.
No unless you are going to rewrite whole EF provider for MSSQL Server (or other database you are using).
Did you actually investigate source of performance problems? The query you showed should be optimized by query optimizer on DB server and it should not have any significant performance impact.
Make sure you have correctly configured indexes and up-to-data statistics.