问题
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