Strange Exception thrown using Dynamic Linq Entity Framework Query

£可爱£侵袭症+ 提交于 2019-12-13 14:12:59

问题


I have a gallery entity framework class,and I'm attempting to use the Dynamic Linq Library posted on ScottGu's blog to query the entity set. The failing line of code reads:

return context.Galleries.OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList();

sidx=="Name", and sord=="desc".

The Gallery object does have a property called "Name". However, when executed, i get the following exception:

'Title' 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 6, column 1.

Does anyone know what this means?


回答1:


"it" alias was the problem so the following code should works:

prefix your filter field name Title as it.Title

I found the answer here .. http://challenge-me.ws/?tag=/Exceptions




回答2:


use: AsQueryable<>

return context.Galleries.AsQueryable().OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList();




回答3:


I found a fix, but it doesnt explain the original issue. The query was in a library, and being referenced from the asp.net mvc application. It compiled fine, but bombed at runtime. The fix was putting the dynamiclinq class in the mvc app itself, returning a plain IQueryable form the library, and doing the filtering in the controller itself. The exact same code worked there. Somehow the separation in the library caused the issue.



来源:https://stackoverflow.com/questions/1180487/strange-exception-thrown-using-dynamic-linq-entity-framework-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!