Linq to Entities does not function with Dynamic Linq.

dynamic-linq linq-to-entities

Question

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...

1
0
7/26/2011 11:23:30 AM

Popular Answer

Test with this code :

var q = adent.

Contacts.OrderBy("it.FirstName"). Select("New(Title, FirstName, LastName)");

0
11/25/2011 4:11:17 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow