独立的DAL设计——特定的和通用的

发布于 2024-09-29 21:29:46 字数 359 浏览 0 评论 0原文

场景:创建一个用于学习目的的应用程序,并试图使其独立于数据库。

我已经研究了很多啤酒屋架构,其中每个数据库都有自己的 dal 以及 SqlCommands 和 DataReaders 等的混合。我不存在明确的正确或错误,但通常在维护、速度等方面考虑到架构.net 应用程序的一面对我来说相当新鲜,您是否倾向于滚动自己的特定 dal 类(例如 beerhouse)或使用类似 dbProviderFactory 之类的东西,其中已经有很多功能了?

使用 System.Data.Common 中的通用类(例如 DbCommand、DbDataReader)与特定的 SqlCommand、SqlDataReader 类等相比是否有任何优点/缺点。

提前致谢。

Scenario: Creating an app for learning purposes and am trying to make it database independent.

I have looked at the beerhouse architecture quite a bit where each database has its own dal an a mixture of SqlCommands and DataReaders etc. I no theres not a definite right or wrong, but generally in terms of maintenance, speed etc baring in mind the architecture side of .net apps is quite new to me, would you lean towards rolling your own specifc dal classes like the beerhouse or use something like the dbProviderFactory where quite a lot of the functionality is already there?

Are there any pros/cons with using the generic classes in System.Data.Common such as DbCommand, DbDataReader, opposed to the specific SqlCommand, SqlDataReader classes etc.

Thanks in advance.

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

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

发布评论

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

评论(1

时光沙漏 2024-10-06 21:29:46

据我所知,直接使用DbDataReader速度更快。但当你想修改你的 UI 时它是不可扩展的。 (例如,让您的 Winforms 和 Webforms 项目使用相同的 DAL)。

在我看来如果你想要更多的灵活性,你可能会失去性能。关键是您(作为开发人员)有责任平衡性能与复杂性/可扩展性。例如,假设您正在为一家公司设计一个 winforms 应用程序。您确信该公司不会更改其数据提供程序(例如从 SQL Server 更改为 Oracle)。这样就无需将程序设计为能够连接到不同的数据提供者。正如他们所说:亲吻。 (保持简单愚蠢!;p)

As far as I know, using DbDataReader directly, is faster. But it's not extensible when you want to modify your UI. (e.g. have your Winforms and Webforms projects using the same DAL).

In my point of view if you want more flexibility, you will probably loose performance. The point is you (as the developer) are responsible to balance performance vs. complexity/extensibility. For example suppose you're designing a winforms application for a company. You're sure that the company will not change its data provider (e.g. from SQL Server to Oracle). Then there's no need to design your program to be able to connect to different data providers. As they say: KISS. ( Keep It Simple Stupid! ;p )

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