生成的实体框架类可以跨多个数据库使用吗?
所以我有同一个数据库的多个副本。有些表略有不同,但我生成 EF 实体所针对的表都是相同的。 EF4 是否支持仅通过交换连接字符串来对不同数据库进行数据库调用,或者它是否以某种方式耦合到生成它的数据库?
So I have multiple copies of the same database. Some of the tables are slightly different, but the ones I'm generating EF entities against are all identical. Does EF4 support making database calls against different databases just by swapping out the connection string or is it coupled somehow to the database it was generated against?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设数据库确实相同,只需交换连接字符串,您就不会有任何痛苦。这样看,.edmx 由三部分组成:
无论您对 db1 还是 db2 使用实体模型都没有关系,只要这些数据库之一用于生成实体模型并且“db1=db2”即可。 EF 在后台生成的用于与数据库通信的 Sql 完全基于 .edmx。因此,只要您的数据库相同(没有问题),就可以基于相同的 .edmx“访问”它们!自己尝试一下吧!
如果您确实对 EF 感兴趣并计划使用它,此(Julie Lerman 编写的实体框架) 是必须阅读
You shouldn't have any pain by simply swapping the connectionstring assuming the databases are really identical. See it this way, the .edmx consists out of three parts:
Whether you use the entity model against db1 or db2 doesn't matter at all as long as one of those db's was used to generate the entity model and "db1=db2". The Sql that EF generates under the hood to communicate with the database is based entirely on the .edmx. So as long as your databases are identical expect no problems, they can be "reached" based upn the same .edmx! Try it yourself!
If you are really interested in EF and planning to use it, this (Programming Entity Framework by Julie Lerman) is a must read