Linqpad 中的 UserQuery 是什么?

New*_*eak 6 linq linqpad c#-4.0 dbcontext

\n

可能的重复:
\n LINQPad 错误:\xe2\x80\x98UserQuery\xe2\x80\x99:无法从密封类型派生\xe2\x80\x98My.Entity.Framework.CustomDataContext\xe2\x80\x99

\n
\n\n\n\n

我正在 LINQPad 4 中使用 C# 表达式作为语言运行此查询

\n\n
from t in typeof(UserQuery).GetProperties()\nwhere t.Name == "tablename"\nfrom c in t.GetValue(this,null).GetType().GetGenericArguments()[0].GetFields()\nselect c.Name\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是当我在 C# Web 应用程序中使用此查询时,它会给出错误,没有 UserQuery 的引用

\n\n
var result = from t in typeof(UserQuery).GetProperties()\n             where t.Name == "tablename"\n             from c in t.GetValue(this,null).GetType().GetGenericArguments()[0].GetFields()\n             select c.Name\n
Run Code Online (Sandbox Code Playgroud)\n\n

而 vs 2012 intellisense 没有选择它的任何参考。请告诉我需要添加哪个库引用来执行上述查询,或者需要创建哪个类对象来引用?

\n\n

目前我使用 EF 5.0 和 DbContext 对象,该对象是通过数据库优先方法创建 EF 数据模型时生成的

\n\n

我更喜欢与 DbContext 相关的答案

\n

Joe*_*ari 1

听起来您正在尝试查询类型化数据上下文的属性。

要使其在 Visual Studio 中正常工作,请将 UserQuery 替换为您键入的 DataContext 的名称。