Question

I have a function in my controller which works fine.

    <HttpGet> _
    <Route("SymbolExists/{symbol}", Name:="symbolexistssymbol")> _
    Function SymbolExists(ByVal symbol As String) As Boolean
        'Return SymbolHelpers.SymbolExists(symbol)
        Return symbCtx.symbols.Count(Function(e) e.Symbol1 = symbol) > 0
    End Function

I need this same function available in my code behind and I have a SymbolHelpers class which houses all those functions. I want to just be able to call the function from the Class in the controller but I get the error below when I do (error shown below and its the exact same code that works in the controller!!)

 Public Shared Function SymbolExists(ByVal symbol) As Boolean
        Using symbCtx As New SymbolsEntities()
            Return symbCtx.symbols.Count(Function(e) e.Symbol1 = symbol) > 0
        End Using
    End Function

***LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.*** 
Was it helpful?

Solution

You are missing the type declaration for symbol in your second code example.

Public Shared Function SymbolExists(ByVal symbol as String) As Boolean

Without the type declaration the compiler seems to default to an Object to Object comparision which LINQ to Entities cannot translate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top