使用动态Linq实体框架查询抛出的奇怪异常

时间:2022-12-27 02:08:44

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:

我有一个gallery实体框架类,我试图使用ScottGu博客上发布的Dynamic Linq Library来查询实体集。失败的代码行读取:

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

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

sidx ==“名称”,和sord ==“desc”。

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

Gallery对象确实有一个名为“Name”的属性。但是,执行时,我得到以下异常:

'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.

无法在当前范围或上下文中解析“标题”。确保所有引用的变量都在范围内,加载了所需的模式,并且正确引用了名称空间。,接近简单标识符,第6行,第1列。

Does anyone know what this means?

有谁知道这意味着什么?

3 个解决方案

#1


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

“它”别名是问题所以以下代码应该工作:

prefix your filter field name Title as it.Title

将过滤器字段名称标题为title.Title

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

我在这里找到答案.. http://challenge-me.ws/?tag=/Exceptions

#2


use: AsQueryable<>

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

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.

我找到了修复,但它没有解释原始问题。查询位于库中,并从asp.net mvc应用程序中引用。它编译得很好,但在运行时遭到轰炸。修复程序是将dynamiclinq类放在mvc app本身中,从库中返回一个简单的IQueryable表单,并在控制器本身中进行过滤。完全相同的代码在那里工作。不知何故,图书馆的分离导致了这个问题。

#1


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

“它”别名是问题所以以下代码应该工作:

prefix your filter field name Title as it.Title

将过滤器字段名称标题为title.Title

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

我在这里找到答案.. http://challenge-me.ws/?tag=/Exceptions

#2


use: AsQueryable<>

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

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.

我找到了修复,但它没有解释原始问题。查询位于库中,并从asp.net mvc应用程序中引用。它编译得很好,但在运行时遭到轰炸。修复程序是将dynamiclinq类放在mvc app本身中,从库中返回一个简单的IQueryable表单,并在控制器本身中进行过滤。完全相同的代码在那里工作。不知何故,图书馆的分离导致了这个问题。