I ran into an annoying issue today while trying to select some records using LINQ to Entities. The code was simple:
Dim ppl = From c In ctx.People Where c.AddedBy = Request("e") Select c
but i kept getting the following error:
"LINQ to Entities does not recognize the method 'System.String get_Item(System.String)' method, and this method cannot be translated into a store expression"
The reason for this lies with the Request variables which i'm using to get the email address from the querystring. Bob Powell found the solution - it seems like the order of how expressions are evaluated has a problem, and that the querystring value is not evaluated at the time that the select statement is built, hence the runtime cannot evaluate the value coming from the querystring (or session/form variables).
The solution is simple, simply create a variable to contain the request variable and use that in the query:
Dim email As String = Request("e")
Dim ppl = From c In ctx.People Where c.AddedBy = email Select c
You can read Bob's post here:
http://bobpowelldotnet.blogspot.com/2009_01_01_archive.html
Dimitri