我正在 .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.
发布评论
评论(4)
至少有两种被广泛接受的设计模式用于封装数据访问:
为了完整起见,我建议您阅读以下书籍:
There are at least two widely accepted design patterns used to encapsulate data access:
For the sake of completeness I suggest you these books:
如果看起来这是一个重要的项目,并且 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.
如上所述,检查存储库和工作单元模式。 强烈推荐福勒和埃文斯的书。 卡尔塞金的读者也是如此,它给了我对刚才提到的书籍的更酷的介绍。 请访问 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
作为 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.