EDMX 连接字符串

发布于 2024-08-21 05:53:25 字数 870 浏览 12 评论 0原文

所以故事是这样的。

我有一个名为 PA.DLL 的项目,其中有一个实体模型(edmx)文件。

在我引用 PA.DLL 的另一个项目中,我将创建 edmx 文件时(自动)创建的连接字符串复制到主应用程序 app.config 中。

但是,当我加载并运行以下几行时:

using (PAEntities analytix = new PAEntities())
           {
...
}

我收到以下错误:

System.ArgumentException: The specified default EntityContainer name 'PAEntities' could not be found in the mapping and metadata information.

有谁知道此错误的原因是什么?

这就是我的连接字符串的配置方式:

<add name="PAEntities" 
    connectionString="metadata=res://*/PAEntities.csdl|res://*/PAEntities.ssdl|res://*/PAEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=XSXSX;Initial Catalog=PA;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

谢谢

so the story is like this.

I have a project, called PA.DLL, which have an entity model inside of it (edmx) file.

In another project which i'm referencing to the PA.DLL, i copied the connection string that was created (automatically) when creating the edmx file into the main app app.config.

however, when i load and run the following lines:

using (PAEntities analytix = new PAEntities())
           {
...
}

i get the following error:

System.ArgumentException: The specified default EntityContainer name 'PAEntities' could not be found in the mapping and metadata information.

Does anyone has any idea what the cause for this error?

This is how my connection string is configured:

<add name="PAEntities" 
    connectionString="metadata=res://*/PAEntities.csdl|res://*/PAEntities.ssdl|res://*/PAEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=XSXSX;Initial Catalog=PA;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2024-08-28 05:53:25

在解决方案资源管理器中,右键单击实体数据模型文件 (.edmx),然后单击“打开方式”。将打开一个对话框,供您选择打开该文件的程序。
选择或双击“XML(文本)编辑器”。

现在您正在查看 EDM 文件的 XML 版本,您可以在其中轻松编辑“EntityContainer”名称。

如果您更改了 webconfig 文件上的连接字符串,请确保“DefaultContainerName”是该 XML 文件中“EntityContainer”部分的名称。

通常,当您更新 *.Designer.cs 文件中的 defaultContainerName 时,它​​不会更新 XML 文件。所以你必须手动完成。

On the Solution Explorer, right click the Entity Data Model file (.edmx) and click 'Open with'. A dialog box will open up to choose a program for you to open the file.
Select or Double click on 'XML (text) Editor'.

Now you re looking at the XML version of the EDM file where you can easily edit the 'EntityContainer' name.

If you have changed the connectionstring on the webconfig file, make sure the 'DefaultContainerName' is the name on section 'EntityContainer' in that XML file.

Usually when you update the defaultContainerName in *.Designer.cs file, it doesn't update the XML file. So you have do it manually.

鹤仙姿 2024-08-28 05:53:25

一种解决方案是将连接字符串放置到使用 DLL 的项目的配置文件中。
另一种是在代码中传递连接字符串(使用PAEntities的参数化构造函数)。

One solution is to place the connection string to the configuration file of the project consuming your DLL.
The other one is to pass the connection string in code (use the parameterized constructor of PAEntities).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文