c# - Linqpad 并从外部库中获取配置字符串
问题描述
我刚开始使用 LinqPad (v5),我喜欢它。
但我有一个问题。我从我的 Web 项目中成功导入了 EntityFramework 连接(ObjectContext),当我尝试像这样实例化它时:
var db = new SISTEM.Models.DataModelContainer();
我收到以下错误:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
我已经向 LinqPad.exe.config 和 LPRun.exe.config 添加了连接字符串(与 web.config 中的相同),但这没有帮助,我得到了同样的错误。
如果我像这样构建 EntityConnectionString:
var ecsb = new EntityConnectionStringBuilder();
ecsb.Provider = "System.Data.SqlClient";
ecsb.ProviderConnectionString = "Persist Security Info=True;Data Source=localhost;initial catalog=BASE;User ID=sa; Password=Elmlodge4;multipleactiveresultsets=True;App=EntityFramework";
ecsb.Metadata = "res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl";
var db = new SISTEM.Models.DataModelContainer(ecsb.ToString());
一切都像魅力一样。
大多数时候,就是这样。直到我需要调用一个位于外部库中的函数,该函数又实例化我的 ObjectContext 期望来自配置的连接字符串,它没有被拾取。
我希望我清楚地解释了我的问题,我将不胜感激任何帮助解决它。
更新:
我的网络配置中的片段:
<connectionStrings>
<add name="DataModelContainer" connectionString="metadata=res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl;provider=System.Data.SqlClient;provider connection string="Persist Security Info=True;Data Source=locahost;initial catalog=BASE;User ID=sa; Password=Elmlodge4;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
我只是将以上内容复制到 LinqPad 配置中,我不确定是否需要。
米洛斯
解决方案
你提到 linqpad.exe.config,但你应该使用 linqpad.config
来自常见问题
我正在引用一个从应用程序配置文件 (app.config) 读取设置的自定义程序集。如何告诉 LINQPad 将其用于我的查询?
最简单的方法是打开查询属性对话框 (F4) 并单击 app.config 选项卡。
或者,您可以在与 LINQPad.exe 相同的文件夹中创建一个名为 linqpad.config 的文件。您在此处放置的任何内容都适用于所有查询(除非您在上面的对话框中覆盖它)。不要将 linqpad.config 与 linqpad.exe.config 混淆:
linqpad.config 用于您的查询。
linqpad.exe.config 用于 LINQPad GUI
推荐阅读
- python - 多处理 VS 多线程,更适合读取和写入数据
- shell - 如何在 shell 脚本中使用二进制数?
- python - 将 argparse 参数分组到(子)字典中
- javascript - 循环中的窗口,并在事件发生时将唯一参数传递给每个窗口。打开加载
- css - CSS - 动态改变字体大小以适应容器的高度
- compilation - 在 Gatling 中运行录制的模拟时,出现错误
- android - ionic 4 菜单不适用于 android 移动应用程序,但适用于桌面
- flowtype - 流动。如何根据函数参数指定联合类型
- java - CloseableHttpAsyncClient 不发出http请求
- angular - 如何以角度制作更新表格?