gpt4 book ai didi

vb.net - 匿名类型,从 if 语句转换为 AsQueryable 然后查询

转载 作者:行者123 更新时间:2023-12-04 06:09:14 26 4
gpt4 key购买 nike

我有这个 if 语句,它将结果作为 AsQueryable 返回到匿名类型:

If (signature = "") Then
testResults = (From TRTable In context.TestResults
Where ((TRTable.Art_no = currentProduct) And (TRTable.Server_time > startDate) And (TRTable.Server_time < endDate))
Select TRTable.Art_no, TRTable.Failed, TRTable.Retested).AsQueryable
ElseIf (signInfo = "out") Then
testResults = (From TRTable In context.TestResults
Where ((TRTable.Art_no = currentProduct) And (TRTable.Server_time > startDate) And (TRTable.Server_time < endDate) And TRTable.Sign <> signature)
Select TRTable.Art_no, TRTable.Failed, TRTable.Retested).AsQueryable
Else
testResults = (From TRTable In context.TestResults
Where ((TRTable.Art_no = currentProduct) And (TRTable.Server_time > startDate) And (TRTable.Server_time < endDate) And TRTable.Sign = signature)
Select TRTable.Art_no, TRTable.Failed, TRTable.Retested).AsQueryable
End If

然后当我做
StatisticsModel.Passed = testResults.Where(Function(p) p.Failed = 0).Count

我得到
Method invocation failed because 'Public Function Where(predicate As String, ParamArray parameters As System.Data.Objects.ObjectParameter()) As System.Data.Objects.ObjectQuery`1[[VB$AnonymousType_3`3[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable`1[[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Nullable(Of VB$AnonymousType_3(Of String,Nullable(Of Decimal),Nullable(Of Decimal)))' cannot be called with these arguments:
Argument matching parameter 'predicate' cannot convert from 'VB$AnonymousDelegate_1(Of Object,Object)' to 'String'.

抱歉,很长的文本行,但我似乎无法弄清楚为什么它不起作用,它在没有 if 语句的情况下工作,但我需要该功能。
谢谢 :)

最佳答案

您正在尝试使用 System.Linq.Queryable.Where扩展方法,但您的代码认为您想要 System.Data.Objects.ObjectQuery.Where .

确保您拥有正确的 Imports System.Linq文件顶部的声明。如果这不起作用,您可能需要直接调用 System.Linq.Queryable.Where(testResults, ...).Count .您也可以使用 Count(predicate)而不是 Where(predicate).Count ,这也可以避免冲突。

关于vb.net - 匿名类型,从 if 语句转换为 AsQueryable 然后查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7977130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com