WCF:从 Oracle 10g、MySQL 和 SQL Server 2008 数据库获取数据的最佳方式?
我正在使用 ASP.NET 4.0 设计一个简单的 C# WCF 服务,并托管在 IIS7 上,.NET 和 Java Web 应用程序和桌面应用程序将使用该服务来提取存储在各种数据库(本地和远程)中的数据。在使用 VS2005 和 asp.net Web 服务几年后,我开始学习如何使用 VS2010 和 WCF,所以我对 WCF 有点菜鸟,但对 Web 服务和 Visual Studio 有所了解。
有没有人对 Visual Studio 2010 中的项目/类/文件设置方面的最佳方法有什么意见,看看我如何最大化代码重用和最小化开发时间,但仍然能够连接到不同的数据库?我有一个用于该服务的 WCF 服务应用程序项目,并生成了一个 WCF 客户端以用于使用 svcutil.exe 进行测试,但现在我需要开始编写数据库访问层代码(或“模型”代码)对于 MVC(如果这是我需要继续的设计路线)。
任何帮助表示赞赏,谢谢!
I am designing a simple C# WCF service using ASP.NET 4.0 and hosted on IIS7, which will be used by .NET and Java web applications and desktop applications to extract data stored in various databases (both local and remote). I am starting to learn how to use VS2010 and WCF after working for a few years on VS2005 and asp.net web services, so am somewhat of a noob to WCF but know a bit about web services and Visual Studio.
Does anyone have opinions on what the best approach would be in terms of project/class/file setup in Visual Studio 2010 to do this, seeing as how I want to maximize code re-use and minimize development time yet still have the ability to connect to the different databases? I have a WCF Service Application project for the service, and have generated a WCF Client to use for testing using svcutil.exe, but now I'm at the point where I need to start writing database access layer code (or "model" code for MVC if that's the design route I need to go down).
Any help appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个数据库在集成时都会有一些麻烦。
您需要开始的第一件事是以 OO(面向对象)方式设计模型,而不是关系数据库方式。
创建这样的模型后,您需要实现映射器层/类会将数据从关系形式映射到 OO 格式。
然后对于每个数据库你需要编写一些数据访问代码。您为数据访问编写的代码量很可能取决于您使用的工具\技术。您可以研究 Entity Framework 或 NHibernate 或其他此类 ORM,以减少访问数据所需的代码。
但请记住,这些 ORM 映射器可能需要进行自己的一组调整才能与 MySQL、Oracle、SQL Server 良好配合。
Each of the databases will have their set of nuisances while integration.
The first thing you need to start with would be to design your model in more of OO (Object Oriented) fashion than relation DB way.
Once such a model is created, you need to implement mapper layer/classes that would map data from a relational form to a OO format.
Then for each DB you need to write some data access code. The amount of code you write for data access may well depend upon the tools\technologies you use. You could look into Entity Framework or NHibernate or other such ORMs to decrease the code required to access data.
But keep in mind these ORM mappers may require their own set of tweaks to work well with MySQL, Oracle, SQL Server.