三层架构,数据库访问层模式 [英] Three tier architecture, database access layer pattern

查看:79
本文介绍了三层架构,数据库访问层模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在设计.NET框架中的体系结构.我使用三层模型来设计我的应用程序,但我对如何正确建模对数据库层的访问方式感到担忧.我对每一层都有单独的DLL.

在我的业务层中,我想访问数据库,例如,以一种新方式添加新注册表,即成员不传递参数中的每个成员,而是将成员全部传递给单个成员.目的.例如:

Hi,

I am designing an architecture in .NET framework. I use the Three tier model to design my application but I have a concern about how is the way to properly model the access to database layer. I have separate DLL for each layer.

In my business layer I want to access the database, for example to add new registry in a way that the members are not passed each one in a parameter but all in a single object. For example:

<br /><br />namespace myapp.bussines_layer<br />{<br />class Point<br />{<br />  int x;<br />  int y;<br /><br />  MyDatabase db = new MyDatabase();<br /><br />  //I want this...<br />  void InsertInDatabase()<br />  {<br />    db.NewRowInDB(this);<br />  }<br /><br />  //... instead of this<br />  void InsertInDatabase()<br />  {<br />    db.NewRowInDB(this.x, this.y);<br />  }<br />}<br />}<br />



事情是这样的,因为Point知道MyDatabase,所以我具有循环依赖关系. MyDatabase必须知道Point才能将Point识别为函数中的参数.

我的想法是否正确地适合访问数据库的良好实践和设计?更好的设计是将所有参数作为本机类型传递(即使当os参数的数量很高时)??

如果有人可以帮助我和/或给我提供有关良好设计模式的参考,我将不胜感激业务层和数据库层之间的连接.

非常感谢.

Julen.



The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function.

Does my idea fit correctly in the good practices and designs to access databases? Is better design to pass all the parameters as native types (even when the amount os parameter is high)??

I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers.

Thank you very much in advance.

Julen.

推荐答案

Julen写道:

我使用树层模型



它是"层" ,如数字3所示,而不是树层".



It''s "three-tier", as in the number 3, not "tree tier".




为了消除循环依赖并遵循最佳实践,最好创建类似于业务实体(在本例中为Point等)的类库项目.并从业务层和数据层两者中进行引用.通过这样做,它有助于实现松散的耦合,重用,模块化等.

希望对您有所帮助!.

问候,
-Vinayak
Hi,

In order to eliminate the circular dependencey and to follow the best practice, it would be better to create the class library project which resembles the business entities( in this case Point etc). and refer this both from Business Layer and the Data Layer. By doing this it helps to achieve loose coupling, re use, modularity etc.

I hope this helps!.

Regards,
-Vinayak


这篇关于三层架构,数据库访问层模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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