3

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?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
midas06
  • 1,991
  • 2
  • 22
  • 43
  • The bug is somewhere else, probably in the query. The line of code you include is simply the line which executes the query (because of the ToList). You see the error surface there, but the real bug is elsewhere. My first guess would be the mapping, but there's not nearly enough code here to tell. – Craig Stuntz Jul 27 '09 at 19:56

3 Answers3

8

"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

Thant Zin
  • 543
  • 5
  • 8
2

use: AsQueryable<>

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

Behruz Tolibov
  • 455
  • 4
  • 7
0

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.

midas06
  • 1,991
  • 2
  • 22
  • 43