动态 Linq 不适用于 Linq to Entities
我正在开发 Linq To 实体的小项目。需要根据用户设置的搜索条件/过滤器来过滤数据。由于过滤/搜索条件可以适用于视图中显示的任何字段,因此我决定使用 Dynamic Linq。
我从 Scotgu 的博客。在我的类中引用了 System.Linq.Dynamic,我创建了一个示例类,它执行如下所示的动态 linq 查询,
AdventureWorksEntities adent = new AdventureWorksEntities();
var q = adent.
Contacts.OrderBy("FirstName").
Select("New(Title, FirstName, LastName)");
var l = q.ToList();
但是,在上面的代码块中,当查询执行时,我收到错误,
“FirstName”无法在当前范围或上下文中解决。确保所有引用的变量都在范围内,加载所需的架构,并且正确引用命名空间。接近简单标识符,第 8 行,第 1 列。
我已经检查了很多关于这方面的帖子,但帮助很少...
任何有关如何解决上述错误的指示都会很棒...谢谢...
PS 对 DataContext 的类似查询工作正常......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下代码进行测试:
Contacts.OrderBy("it.FirstName")。
选择(“新(标题,名字,姓氏)”);
Test with this code :
Contacts.OrderBy("it.FirstName").
Select("New(Title, FirstName, LastName)");