跨多个项目重用数据库访问以确保更新时不会破坏任何项目的最佳方法是什么?
我可能已经在多个项目中编写了 4-5 次相同的 LINQ to SQL 语句。我什至不想粘贴它。我们将 DBML 文件与 Repository 类结合使用。我想在多个项目之间共享同一个库,但我也想轻松更新它并确保它不会破坏任何项目。有什么好的方法可以做到这一点?如果我必须改变我的方法也没关系,我不需要与 LINQ to SQL 和 DBML 结合。
我们有控制台应用程序和 MVC Web 应用程序,它们都使用各自的 DBML 风格来访问数据库,并且有时主要的数据库更新会破坏它们。
另外,由于目前每个项目都从自身访问数据库,而数据库有时位于另一台服务器上,等等。是否有可能将数据库层从每个项目中全部消除?如果我可以通过我的其他应用程序可以直接使用的集中式应用程序来管理所有数据库访问,而不是直接调用数据库,那么它可能会帮助解决上述问题,并且更好地保证安全性和数据完整性。
有什么想法吗?
I have probably written the same LINQ to SQL statement 4-5 times across multiple projects. I don't even want to have to paste it. We use DBML files combined with Repository classes. I would like to share the same Library across multiple projects, but I also want to easily update it and ensure it doesn't break any of the projects. What is a good way to do this? It is OK if I have to change my approach, I do not need to be married to LINQ to SQL and DBML.
We have both console apps and MVC web apps accessing the database with their own flavor of the DBML, and there have been times when a major DB update has broken them.
Also, since currently each project accesses the DB from itself, which is sometimes on another server, etc. Would it be possible to eliminate the DB layer from being within each project all together? It might help the problem above and be better for security and data integrity if I could manage all the database access through a centralized application that my other applications could use directly rather than calling the database directly.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我处理这个问题的方法是使用 WCF 数据服务。我将数据模型和服务放在一个项目中,并将其托管在 IIS 上。我的其他项目(无论它们是什么)只需添加对 URI 的服务引用,然后通过网络访问所需的数据。我的数据库工作全部发生在服务上,我的个人项目根本不接触数据库 - 他们甚至不知道数据库存在。
它运行得很好,但 WCF 存在一些“问题”。您甚至可以创建“WebGet”方法来通过服务公开常用的方法。
如果您想查看一些示例代码,请告诉我:-)
The way I handle this is using WCF Data Services. I have my data models and services in one project and host this on IIS. My other projects (whatever they may be) simply add a service reference to the URI and then access data it needs over the wire. My database stuff happens all on the service, my individual projects don't touch the database at all - they don't even know a database exists.
It's working out pretty well but there are a few "gotchas" with WCF. You can even create "WebGet" methods to expose commonly used methods via the service.
Let me know if you want to see some example code :-)