I am working on small project which Linq To entities. There is a requirement to filter the data based on the search criteria/filter which is set by the user. Since the filter/search criteria can be for any of the fields which are displayed in the view, I decided to use Dynamic Linq.
I downloaded the library from Scotgu's blog. Referenced the System.Linq.Dynamic in my class and i have created a sample class which does a dynamic linq query like the below,
AdventureWorksEntities adent = new AdventureWorksEntities(); var q = adent. Contacts.OrderBy("FirstName"). Select("New(Title, FirstName, LastName)"); var l = q.ToList();
However, in the above code block, when the query executes, I get the error,
'FirstName' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 8, column 1.
I have check quite a few posts on this regard but with very less help...
Any pointers on how to resolve the above error will be great... Thanks...
P.S. A similar query on the DataContext is working fine...
Test with this code :
var q = adent.
Contacts.OrderBy("it.FirstName"). Select("New(Title, FirstName, LastName)");