n层应用程序中的动态数据访问层 [英] Dynamic Data Access Layer in an n-tier application

查看:75
本文介绍了n层应用程序中的动态数据访问层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我最近开始用C#构建n层应用程序(表示层,业务层和数据访问层),一切都很好.在我进入数据访问层之前,目前我的DAL是静态的,因为对于我数据库中的每个表,我都有一个数据访问层,其中具有针对该表的不同select,update,delete和insert语句,例如,我有一个客户数据访问层和订单数据访问层.现在,我的问题是如何使数据访问层动态化,换句话说,就是仅使用一个动态数据访问层,该层包含所有业务层都可以用来选择,插入,更新或删除数据的动态方法.简而言之,我希望对数据库中的每个表仅使用一个DAL,而不是多个.目的是为了重用能力.请尝试帮助.我将不胜感激!

Good day fellow coders, I recently started to build n-tier applications (Presentation Layer, Business Layer and Data Access Layer) in C# and all is well. Until I came to data access layer, at the moment my DAL is static in the sense that for each table in my database I have a data access layer with the different select, update, delete and insert statements for that table for example I have a client data access layer and an order data access layer. Now the question I have is how to make a data access layer dynamic in other words only to use one dynamic data access layer which contains dynamic methods all the business layers can use to select,insert,update or delete data. Put simply I wish to use only one DAL instead of multiple for each table in the database. The purpose is for re-use ability. Please try to help. I would appreciate it!

推荐答案

正常答案是,这不是一个好主意.

如果您的应用程序非常简单,那么CRUD procs就可以帮助您解决问题.

而且,通过简单的应用程序,调试,理解和维护变得更加容易.因此,没有必要尝试驱动通用层.

在更复杂的应用程序中,会有更多复杂的操作.因此,除了CRUD之外还需要proc.全面增加的复杂性扩展到维护.因此,通用层是一个更好的解决方案,因为它至少在某种程度上更有可能降低总体维护成本(在一个区域中进行复杂性交易,而在另一区域中进行复杂性交易.)

现在,如果您想使用另一种方法来学习如何做,并且这种方法似乎会使公司受益(或者也许不是一个因素),那么您可以研究替代方法.

如果且仅在这种情况下,您才可能要看一下nHibernate.
Normal answer is that that isn''t a good idea.

If you have a rather simple application then you can get by with nothing more than CRUD procs.

And with a simple application then it is much easier to debug, understand and maintain. So there isn''t any point to attempt to drive to a generic layer.

In a more complex application there are more complex operations. Thus procs besides CRUD will be needed. The increased complexity is across the board and that extends to maintenance. A generic layer is thus a better solution as it is is more likely, at least to some degree, to reduce overall maintenance costs (trading complexity in one area for complexity in another.)

Now if you want to use another approach to learn how to do it and it seems likely that such an approach would benefit the company (or perhaps that is not a factor) then you might investigate alternatives.

If and only if that is the case then you might want to look at nHibernate.


因此"?

您的第二条陈述与第一条陈述不符.
理解通用层并不容易.

除此之外,我还提到了"nHibernate",它是一种开源通用解决方案.
"Hence"?

Your second statement does not follow from the first.
It is NOT easier to understand a generic layer.

Other than that I mentioned "nHibernate" which an open source generic solution.


这篇关于n层应用程序中的动态数据访问层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆