我有一个数据库,其中包含一个表值函数,用于实现 CONTAINSTABLE 查询。它看起来像这样:
CREATE Function [dbo].[FreeTextSearch_Usage]
(@SearchString varchar(1024) )
returns table
AS
return Select top 750 rank, internalid, myVal1, myVal2, myVal3
FROM (SELECT K.RANK, C.internalid, C.Realid as myVal1,
D.valStr2 as myVal2, D.valStr3 as myVal3
FROM [dbo].[idmapping] AS C
INNER JOIN
CONTAINSTABLE ( [dbo].myTable1,
myColumn1,
@SearchString
) AS K ON C.[internalid] = K.[KEY]
join [dbo].[valTbl] as D on
D.valID = K.[key]
union --- more CONTAINSTABLE queries
) AS Match
ORDER BY rank desc
这可以工作并已作为独立代码进行测试,并且在使用 t–sql select * from FreeTextSearch_Usage('keyword') 调用时也可以工作
但现在我试图从我的 C# 代码中调用它,其中数据库被声明(通过代码生成自动)为
public partial class myDBContextContainer : DbContext
{
public myDBContextContainer() : base (name=myDBContextContainer)
{}
o o o
[DbFunction(myDBContextContainer, FreeTextSearch_Usage)]
public virtual IQueryable<FreeTextSearch_Usage_Result> FreeTextSearch_Usage ( string searchString )
{
var searchStringParameter = new ObjectParameter ("SearchString", SearchString );
return ((IObjectContextAdapter)this.....very long - will reproduce if needed
}
因此,在我的代码中,我执行以下操作:
using( var myDBctx = new myDBContextContainer () )
{
try
{
var usageList = myDBctx.FreeTextSearch_Usage("'keyword'").ToList();
var usageList2 = from s in myDBctx.FreeTextSearch_Usage( "keyword" )
select new List<usageListType> {};
}
catch (e )
并且几乎无论我作为关键字传递什么,它都会引发异常,内部异常值为“全文查询字符串的全文查询参数无效”
因此,如果我传递“keyword”形式的字符串,如果传递“keywod”形式的字符串,则会出现异常,如果传递“'FORMSOF(INFLECTIONAL,'keyword')' " 如果我传递格式为 ""FORMSOF(INFLECTIONAL, 'keyword')"" 的字符串,我会得到一个异常。我得到一个异常
如何调试底层函数以找出传递给它的引发异常的内容?
或者,我在声明中做错了什么?