多个 edmx 文件的 Linq-To-Entities 连接字符串
我有一个 dot net 4.0 DAL 库项目,其中包含三个 edmx 文件。我选择将数据模型拆分为三个文件,因为我的数据库中有很多表,从我在 Stackoverflow 上读到的内容来看,这样做似乎是最佳实践。
但现在我的 App.config 中有三个连接字符串条目,它们基本上使用相同的数据库连接。我能否以某种方式回到旧的 ado.net 风格,在我的配置文件中只有一个连接字符串?
谢谢, 延斯
I have a dot net 4.0 DAL library project that contains three edmx files. I chose to split my data model in three files because there are many tables in my db, and from what I've read here at Stackoverflow it seemed best practice to do so.
But now I have three connection string entries in my App.config that basically uses the same database connection. Can I somehow get back to the old ado.net style with only one connection string in my config files?
Thanks,
Jens
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,您可以使用 EntityConnectionStringBuilder从存储在配置文件中的“常规”连接字符串构建三个单独的连接字符串。
您会得到类似的结果:
您可以创建三个 EntityConnectionString 并更改每个实体连接字符串的 MetaData 属性以指向您的模型。
但请注意,这会导致代码中的连接字符串部分被硬编码。
In your code you could use the EntityConnectionStringBuilder to build the three separate connection strings from a 'regular' connection string that's stored in your config file.
You would get something like:
You can create three EntityConnectionStrings and change the MetaData property on each one to point to your Model.
But be aware that this would lead to a hardcoded part of your connection string in code.