Strange exception caused by using Dynamic Linq Entity Framework query

I have a gallery entity framework class, and I'm trying to use the Dynamic Linq library hosted on ScottGu's blog to request a set of objects. A faulty line of code reads:

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

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

The Gallery object has a Name property. However, upon execution, I get the following exception:

A "name" may not be permitted in the current area or context. Ensure that all referenced variables are in the area that require schema loading, and that the namespaces are correctly specified., Near a simple identifier, row 6, column 1.

Does anyone know what that means?

+3
source share
3 answers

I found a fix, but it does not explain the original problem. The request was in the library and referenced the asp.net mvc application. It compiled fine, but was hacked at runtime. The fix was that the dynamiclinq class was placed in the mvc application, returning the regular IQueryable library and performing filtering in the controller itself. The same code worked there. Somehow, sharing in the library caused a problem.

0
source

"this" was the problem, so the following code should work:

specify the name of the Header filter field as it.Title

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

+8
source

use: AsQueryable < >

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

+2

Source: https://habr.com/ru/post/1713506/


All Articles