使用LinqPad:Argument Exception查询Ef上下文

时间:2012-02-17 11:29:10

标签: entity-framework entity-framework-4 linqpad

我在linqpad中添加了Ef连接,如下面的enter image description here
正如您所看到的,已成功添加连接,但是当我想查询此连接时,我会收到以下异常

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

它似乎与连接字符串连接,但它将如何解决,我不知道。上下文在asp.net mvc项目中定义(没有单独的数据访问项目),连接字符串像往常一样在web.Config文件中

2 个答案:

答案 0 :(得分:1)

我有同样的问题,我可以按照这里的说明解决它

1)通过以下方法找到LINQPad用于其配置文件的路径:AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.Dump()

  

这为我返回了以下内容:C:\ Program Files \ LINQPad4 \ LINQPad.config

     
      
  1. 我很惊讶这返回LINQPad.config而不是LINQPad.exe.config   这是您通常所期望的,因为大多数.NET应用程序都将其命名为>文件与可执行文件相同。

  2.   
  3. 将您的App.config复制到上面命名配置的位置   归档你的任何归还。在我的例子中,它是LINQPad.config

  4.   
  5. 关闭LINQPad或已打开的TAB以执行程序集并重新打开以使LINQPad读取配置文件。

  6.   

http://coding.infoconex.com/post/2012/06/01/Getting-LINQPad-to-read-your-applications-AppConfig-settings.aspx

答案 1 :(得分:0)

最新版本的LINQPad支持使用DbContext或ObjectContext直接连接到项目。使用该连接类型,您可以在设置连接时指定app.config / web.config。

http://www.kevinlabranche.com/blog/ConnectingLinqPadToEntityFrameworkCodeFirst.aspx