实体框架重用edmx实体连接字符串
尝试了解实体框架和生成的 edmx 文件。
在将 edmx 文件添加到我的解决方案时,它添加了以下部分
<add name="MyEntities" connectionString="metadata=res://*/Model.MyModel.csdl|
res://*/Model.MyModel.ssdl|
res://*/Model.MyModel.msl;provider=System.Data.SqlClient;provider connection
string="Server=xxx;Database=mydb;
UserID=xxxx;Password=xx;Trusted_Connection=False;Encrypt=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
一切正常,直到我需要删除 edmx 并重新添加它。保持上述配置部分不变并选择跳过 “将 web.config 中的实体连接设置另存为:MyEntities”会导致问题。
该解决方案不再识别我的对象上下文 - MyEntities。它给了我一个通用的“实体”。我检查了designer.cs文件,果然如此 它充满了实体而不是 MyEntities。如果有人能够阐明此映射的工作原理以及每次我删除并重新添加相同的 edmx 时如何不必编辑配置文件,那就太好了。
Trying to understand entity framework and the edmx files generated.
While adding a edmx file to my solution it adds the following section
<add name="MyEntities" connectionString="metadata=res://*/Model.MyModel.csdl|
res://*/Model.MyModel.ssdl|
res://*/Model.MyModel.msl;provider=System.Data.SqlClient;provider connection
string="Server=xxx;Database=mydb;
UserID=xxxx;Password=xx;Trusted_Connection=False;Encrypt=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Everything works fine until I need to delete the edmx and re-add it. Leaving the above config section intact AND choosing to skip the
"Save entity connection settings in web.config as: MyEntities" causes issues.
The solution no longer recognizes my object context - MyEntities. It gives me a generic "Entities" instead. I check the designer.cs file and it sure enough
its peppered with Entities instead of MyEntities. Would be great if someone could throw some light on how this mapping works and how everytime I delete and re-add the same edmx I would not have to edit the config file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在读取 edmx 文件之前,只需删除(或在其他地方备份)配置文件中的部分以重用连接字符串名称。
before you readd the edmx file, just remove(or backup it elsewhere) the <add> section from the config file to reuse the connectionstring name.