custom software and consulting
using the latest Microsoft technologies

Specialized software and web development
Login www.insidelogic.nl « Blog

  Search

aug 20

Written by: Dimitri Stoikof
20-8-2009 12:41 

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

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel