所以我正在使用LINQKIT找到here
我正在尝试在我的一个列CID上创建一个表达式。
谓词看起来像这样:
Dim cid As String = "11R"
Dim predicate = PredicateBuilder.[New](Of uv_Manifest).And(Function(x) x.CID = cid)
它返回一个如下所示的谓词:
{x => (CompareString(x.CID, value(FSVendor_RefactoredRepository.ManifestManager+_Closure$__2-0).$VB$Local_cid, False) == 0)}
这将返回如下所示的SQL:
SELECT
[Extent1].[CID] AS [CID],
FROM (SELECT
[uv_Manifest].[CID] AS [CID],
FROM [dbo].[uv_Manifest] AS [uv_Manifest]) AS [Extent1]
WHERE ([Extent1].[CID] = @p__linq__0) OR (([Extent1].[CID] IS NULL) AND (@p__linq__0 IS NULL))
当我在visual studio中运行此语句时会超时,而如果我将谓词硬编码为这样:
Dim predicate = PredicateBuilder.[New](Of uv_Manifest).And(Function(x) x.CID = "11R")
它工作正常并给我一个看起来像这样的谓词:
{x => (CompareString(x.CID, "11R", False) == 0)}
SQL看起来像这样:
SELECT
[Extent1].[CID] AS [CID]
FROM (SELECT
[uv_Manifest].[CID] AS [CID]
FROM [dbo].[uv_Manifest] AS [uv_Manifest]) AS [Extent1]
WHERE '11R' = [Extent1].[CID]
它执行得很好。
这是我的LINQ行:
Dim q = webDataContext.uv_Manifest.AsExpandable().Where(filters)
为什么当我将值更改为硬编码时,它按预期工作,但是当我不这样做时,它不会创建正确的SQL语句,我该如何解决这个问题?