I have this if statement, which returns the result as a AsQueryable to an anonymous type:
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
And then when I do
StatisticsModel.Passed = testResults.Where(Function(p) p.Failed = 0).Count
I get
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'.
Sorry for the long line of text, but I can’t seem to figure out why it isn’t working, it was working without the if statement, but I need that functionality.
Thank you 🙂
You are trying to use the
System.Linq.Queryable.Whereextension method, but your code thinks you wantSystem.Data.Objects.ObjectQuery.Where.Make sure you have the correct
Imports System.Linqstatement at the top of your file. If that doesn’t work, you might have to directly callSystem.Linq.Queryable.Where(testResults, ...).Count. You could also useCount(predicate)instead ofWhere(predicate).Count, which might also avoid the conflict.