使用动态Linq实体框架查询引发奇怪的异常 [英] Strange Exception thrown using Dynamic Linq Entity Framework Query

查看:97
本文介绍了使用动态Linq实体框架查询引发奇怪的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个画廊实体框架类,并且我试图使用ScottGu博客上发布的Dynamic Linq库查询实体集. 失败的代码行显示为:

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 ==名称",和sord =="desc".

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

Gallery对象确实具有一个名为名称"的属性.但是,执行时,出现以下异常:

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

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

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

推荐答案

我找到了一个修复程序,但没有解释原始问题.该查询在一个库中,并从asp.net mvc应用程序中引用.它编译良好,但在运行时遭到轰炸. 解决方法是将dynamiclinq类放入mvc应用程序本身,从库中返回一个普通的IQueryable,并在控制器本身中进行过滤.完全相同的代码在那里工作.在某种程度上,库中的分离导致了问题.

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.

这篇关于使用动态Linq实体框架查询引发奇怪的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆