如何封装数据库访问?

发布于 2024-07-23 11:21:23 字数 276 浏览 7 评论 0 原文

我正在 .NET 中开发一个事务应用程序,并且希望获得一些有关如何正确封装数据库访问的信息,以便:

  • 我没有所有连接字符串 调用
  • 对同一个存储的多次 来自不同函数的过程
  • 或更糟糕的是,多个存储 程序不同 我有

兴趣知道使用像 NHibernate 这样的 ORM 是否有用,因为它可能只会为快速变化的数据模型增加另一层复杂性,并且需要在紧迫的时间内生成工件。

我对 ORM 包以外的方法或模式更感兴趣。

I am developing a transactional application in .NET and would like to get some input on how to properly encapsulate database access so that:

  • I don't have connection strings all
    over the place
  • Multiple calls to the same stored
    procedure from different functions
  • or WORSE, multiple stored
    procedures that are different by a
    single column

I am interested in knowing if using an ORM like NHibernate is useful, as it may just add another layer of complexity to a rapidly changing data model, and artifacts need to be produced on a tight schedule.

I am more interested in methods or patterns OTHER than ORM packages.

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

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

发布评论

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

评论(4

野味少女 2024-07-30 11:21:23

至少有两种被广泛接受的设计模式用于封装数据访问:

  • 存储库 (DDD)
  • DAO(数据访问对象)

为了完整起见,我建议您阅读以下书籍:

There are at least two widely accepted design patterns used to encapsulate data access:

  • repository (DDD)
  • DAO (Data Access Object)

For the sake of completeness I suggest you these books:

季末如歌 2024-07-30 11:21:23

如果看起来这是一个重要的项目,并且 DAL 是一个主要风险因素,那么请让以前做过该项目的人参与其中。 你是完全正确的,有太多的方法可以在没有丰富经验的情况下尝试第一次就把事情做好,从而导致偏离轨道。

有很多模式可以实现这一点,但我会寻找拥有一组简单且定义良好的模式且完全熟悉的人。

If, as it appears, this is an important project and the DAL is a major risk factor, get someone involved who has done it before. You're exactly right that there are too many ways to run off the rails by trying to get this right the first time without solid experience.

There are any number of patterns for accomplishing this, but I'd look for someone who has a simple set of well-defined patterns they are fully comfortable with.

热风软妹 2024-07-30 11:21:23

如上所述,检查存储库和工作单元模式。 强烈推荐福勒和埃文斯的书。 卡尔塞金的读者也是如此,它给了我对刚才提到的书籍的更酷的介绍。 请访问 http://codebetter .com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

as stated above, check out the repository and unit of work patterns. the books by fowler and evans are highly recommended. so is karl seguin's reader which gave me a cooler introduction to the just mentioned books. grab it at http://codebetter.com/blogs/karlseguin/archive/2008/06/24/foundations-of-programming-ebook.aspx

天邊彩虹 2024-07-30 11:21:23

作为 Java 开发人员,我建议阅读有关 jdbc 模板的内容,尽管它不是 .NET,但您可以了解 Spring 框架如何封装数据访问层并获得一些想法。

As Java Developer, i could suggest to read about jdbc templates, despite of it s'n not .NET you could learn how Spring framework encapsulates data access tier and get some ideas.

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