Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Exception thrown using Dynamic Linq Entity Framework Query

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?

like image 816
midas06 Avatar asked Dec 29 '25 22:12

midas06


2 Answers

"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

like image 117
Thant Zin Avatar answered Dec 31 '25 13:12

Thant Zin


use: AsQueryable<>

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

like image 23
Behruz Tolibov Avatar answered Dec 31 '25 13:12

Behruz Tolibov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!