简体   繁体   English

链接LINQ IQueryable,并以存储过程结束

[英]Chain LINQ IQueryable, and end with Stored Procedure

I'm chaining search criteria in my application through IQueryable extension methods, eg: 我通过IQueryable扩展方法在应用程序中链接搜索条件,例如:

public static IQueryable<Fish> AtAge (this IQueryable<Fish> fish, Int32 age)
{ 
    return fish.Where(f => f.Age == age);
}

However, I also have a full text search stored procedure: 但是,我也有一个全文本搜索存储过程:

CREATE PROCEDURE [dbo].[Fishes_FullTextSearch]
@searchtext nvarchar(4000),
@limitcount int
AS
SELECT Fishes.* FROM Fishes
  INNER JOIN CONTAINSTABLE(Fishes, *, @searchtext, @limitcount)
  AS KEY_TBL ON Fishes.Id = KEY_TBL.[KEY]
  ORDER BY KEY_TBL.[Rank]

The stored procedure obviously doesn't return IQueryable, however, is it possible to somehow limit the result set for the stored procedure using IQueryable's? 该存储过程显然不会返回IQueryable,但是,是否有可能使用IQueryable的方式以某种方式限制该存储过程的结果集?

I'm envisioning something like .AtAge(5).AboveWeight(100).Fishes_FulltextSearch("abc"). 我正在设想类似.AtAge(5).AboveWeight(100).Fishes_FulltextSearch(“ abc”)之类的东西。

In this case, the fulltext search should execute on a smaller subset of my Fishes table (narrowed by Age and Weight). 在这种情况下,全文搜索应在我的Fishes表的较小子集上执行(按年龄和体重缩小)。

Is something like this possible? 这样的事情可能吗? Sample code? 样例代码?

I think that it might work if you 我认为如果您

  • create another extension method for Fishes_FulltextSearch("abc") Fishes_FulltextSearch("abc")创建另一个扩展方法
  • inside it, you insert the result set of the previos methods (AtAge and AboveWeight) to a temporal table 在其中,您将previos方法的结果集(AtAge和AboveWeight)插入到时态表中
  • work with this temporal table inside the stored procedure 在存储过程中使用此时态表
  • return from the stored procedure the desired result set 从存储过程中返回所需的结果集
  • and return from the new extension method the result set of the stored procedure. 并从新的扩展方法返回存储过程的结果集。

Hope this helps. 希望这可以帮助。

如果可以在视图中使用ContainsTable,则-that-返回IQueryable ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM