Reputation: 4432
I had a code segment on an asp.net page in the code-behind file. I decided to move it into a public subroutine in a module (general_functions.vb). Once I did this, however, the code no longer works - it throws an error.
On the original code-behind I replaced the original code with a call like so:
DeleteResidency(people_id, semester, year)
Now in my general_functions.vb I created a public subroutine like follows:
Public Sub DeleteResidency(delpeople_id, delsemester, delyear)
Using dbContext as pbu_housingEntities = New pbu_housingEntities
Dim remove_selection = (From p in dbContext.Residents _
Where p.people_code_id = delpeople_id _
Where p.year = delyear _
Where p.semester = delsemester _
Order By p.id Descending _
Select p).FirstOrDefault
End Using
End Sub
There is more code to it than that, but the code above is what throws the error. The error I get is:
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.
Can anyone help me understand why this is occurring?
Upvotes: 10
Views: 4025
Reputation: 9193
Explicitly type your parameters in the definition of the DeleteResidency Sub Routine. This leaves less for the compiler to infer and prevents these types of errors.
Upvotes: 12