I\'m using LINQ to SQL to get a search result of a FullTextSearch stored procedure in Sql server 2008. I dragged the procedure from the server explorer to the designer, and
Since this is executing a stored procedure, all your lovely Skip
/ Take
is largely redundant anyway... it has no choice but to bring all the data back (stored procedure calls are non-composable). The only thing it can do is not materialize objects for some of them.
I wonder if the better approach would be to refactor the code to make two calls:
int result = repository.FullTextSearchCount(searchText);
var result = repository.FullTextSearch(searchText, skip, take); // or similar
i.e. make the paging parameters part of the SPROC (and to the filtering at the database, using ROW_NUMBER()
/ OVER(...)
, or table-variables, temp-tables, etc) - or alternatively something similar with an OUTPUT
parameter in the sproc:
int? count = null;
var result = repository.FullTextSearch(searchText, skip, take, ref count);
(I seem to recall that OUTPUT
becomes ref
, since TSQL OUTPUT
is really input+output)