2
我有事如下表像来搜索一些文字:我可以将IQueryable <>传递给表值函数吗?
SearchedTextTable
Id int primary key
Text nvarchar(max)
Code int
文字是全文索引的,所以我做了如下表值函数与LinqToSQL工作:
ALTER FUNCTION [dbo].[SearchText] (@keywords nvarchar(4000))
returns @results table (Id int not null)
as
begin
INSERT @results
SELECT
Id
from SearchedTextTable
where contains(Text,@keywords)
return;
end;
我想要做的是在搜索文本之前应用一些条件,如下面的代码:
注意:条件实际上有点复杂,所以我不想把它们放到表值函数中。
using(var contetxt= new FooDataContext())
{
var list = context.SearchedTextTable.Where(x => x.Code==code);
var results = context.SearchText(list, keywords).ToList();
}
和SEARCHTEXT功能应该是这样的:
ALTER FUNCTION [dbo].[SearchText] (@table table, @keywords nvarchar(4000))
returns @results table (Id int not null)
as
begin
INSERT @results
SELECT
Id
from @table
where contains(Text,@keywords)
return;
end;
这可能吗?如果是的话,你能告诉我如何?
由于提前,
柳
编辑
一些测试后,似乎性能也不影响什么,如果我做全文搜索前设置一些条件。他们都返回少于10毫秒。