数据库中立的 .NET 应用程序

发布于 2024-08-10 16:38:12 字数 346 浏览 3 评论 0原文

许多产品开发人员希望编写一个 .NET 应用程序,使其能够与任何流行的 RDBMS(例如 SQL Server、oracle、DB2、MySql)无缝协作。如果我们使用数据应用程序块,它会根据配置动态选择数据库驱动程序(OracleClient、SQLClient 或 OleDBClient)。

然而,所有数据库都有自己的 SQL 风格。存在一些细微的差异,阻碍了一种 SQL 代码库的通用性 - 函数名称不同、处理日期的方式不同、处理 Identity 列的方式不同等等。

人们可以使用 Data Direct 的第三方产品来使用预定义的转义序列编写数据库中性代码。

Microsoft 是否有任何工具或产品可以解决此问题?

Many product developers want to write a .NET application which will work seamlessly with any popular RDBMS like SQL server, oracle, DB2 , MySql. If we use the Data application block it dynamically picks the database driver (OracleClient, SQLClient or OleDBClient) based on configuration.

However, all databases have their own flavours of SQL. There are subtle differences which prevent one SQL code base to be used universally - the function names are different, the way dates are handled are different, the way Identity columns handled are different and so on.

One could use a third party product from Data Direct to write DB neutral code using predefined escape sequences.

Are there any tools or products from Microsoft which addresses this problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别再吹冷风 2024-08-17 16:38:13

Microsoft ADO.NET 实体框架 是一个Microsoft 的对象关系映射框架,旨在让您编写以下代码:某种程度上)与数据库无关。所有主要的 DBMS 都支持实体框架,尽管对于许多(例如 MySQL、Postgres),您需要下载与 .NET Framework 安装分开的东西。

注意:我还没有使用 O/RM 工具处理过一个大型项目,其中至少没有一种情况需要我们使用本机 SQL——无论是为了特定于数据库的功能还是出于性能原因(需要)以特定方式编写查询以获得良好的查询计划)。但良好的 O/RM 在大多数情况下都可以避免编写 SQL。

也就是说,实体框架的当前版本在许多方面都相当有限——其他 O/RM 框架,例如 NHibernateSubSonic等就成熟多了,这里的“成熟”就是支持更深入的 DBMS 功能,而无需使用本机 SQL、更广泛的社区支持、更好的性能等。

这是我礼貌的说法,对于现实世界中相对复杂的项目,我不认为相对于其他可用的 O/RM 工具,当前版本的实体框架是最好的方法。

显然,即将推出的 .NET 4.0/VS2010 版本的 Microsoft Entity Framework 有了很大改进,因此声明明年上述情况可能不成立。例如,新的实体框架添加了对 DDL 的支持,因此您可以以独立于 DBMS 的方式创建表和索引。此外,.NET 4.0 实体框架正在利用一项名为 T4 模板 的炫酷功能,该功能是一个在构建时自动生成代码的巧妙功能,这对于像 O/RM 包装器这样需要与外部数据库模式保持同步的东西很重要——并且应该比它产生更好的(也称为预编译的)性能使用 O/RM 工具,直到运行时才知道数据库列的类型。

The Microsoft ADO.NET Entity Framework is an Object-Relational Mapping framework from Microsoft which is designed to let you write code which is (somewhat) DB-agnostic. All major DBMS's have support for the Entity Framework, although for many (e.g. MySQL, Postgres) you'll need to download something separate from your .NET Framework install.

Note: I have yet to work on a single large project using an O/RM tool where there wasn't at least one case where we had to shell out to native SQL-- either for DB-specific functionality or for performance reasons (needed to write a query in a particular way to get a good query plan). But a good O/RM can work most of the time to prevent having to write SQL.

That said, the current version of the Entity Framework is pretty limited in a number of dimensions-- other O/RM frameworks like NHibernate, SubSonic, etc. are much more mature, where "mature" means support a deeper range of DBMS features without having to shell out to native SQL, wider community support, better performance, etc.

This is my polite way of saying that, for a real-world, relatively complex project, I don't think that the current version of the Entity Framework is the best way to go relative to the other O/RM tools available.

Apparently, the upcoming .NET 4.0/VS2010 version of the Microsoft Entity Framework is much improved, so the statement above may not be true next year. The new Entity Framework adds support for DDL, for example, so you can create tables and indexes in a DBMS-independent way. Also, the .NET 4.0 Entity Framework is leveraging a cool feature called T4 Templates, which is a neat feature to auto-generate code at build time, which is important for things like O/RM wrappers which need to be kept in sync with an external DB schema-- and which should yield better (aka pre-compiled) performance than do O/RM tools which don't know the types of database columns until runtime.

┼── 2024-08-17 16:38:13

据我了解,您正在寻找用于编写独立于 RDBMS 的 SQL 的工具,而不是 ORM。这是一个非常实际的问题,不同的 ORM 供应商以不同的方式解决了这个问题。我只能提到 Xtective SQL DOM 工具,这是为他们的 ORM 开发的- DataObjects.Net。它是 SQL 的抽象,允许使用全功能 DOM 模型编写查询。目前,SQL DOM 并未与 DataObjects.Net 分开推广,但它是一个开源产品,您当然可以向其作者询问。据我所知,它在一些第三方项目中已成功使用。

As I've understood you are looking for tool for writing RDBMS-independent SQL, but not an ORM. This is very actual problem solved by different ORM vendors in different ways. I just can mention Xtensive SQL DOM tool, that was developed for their ORM - DataObjects.Net. It is an abstraction over SQL allowing to write queries using full-featured DOM model. At this moment SQL DOM is not promoted separately from DataObjects.Net, but it is an open source product and you surely can ask its authors about it. As far as I know it is successfully used in some third-party projects.

沫离伤花 2024-08-17 16:38:13

不是直接来自微软。这些工具通常称为对象关系映射器或简称 ORM。例如,NHibernate 是一种常见且广泛使用的 ORM,它非常适合您的需求。当然,还有其他商业产品,如 Telerik OpenAccess ORM、DevExpress XPO 或 RemObjects DataAbstract,它们将帮助您摆脱数据库的束缚。

Not directly from Microsoft. Those tools are commonly named Object-Relational Mappers or short ORM. NHibernate, for instance, is a common and widely used ORM that is very sure to fit your needs. Of course there are other commercial products like Telerik OpenAccess ORM, DevExpress XPO or RemObjects DataAbstract which will help you to be database agnostic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文