如何在 N 层架构中维护事务 [英] How To Maintain Transaction in N-Tier Architecture
问题描述
我正在 N 层架构中开发应用程序.众所周知,我们需要在插入/更新/删除操作的同时实现事务.请告诉我如何在 N 层架构的 c#.net 中使用事务.我的架构是这样的Applicationform->middle_Layre->Factory->DataAccessLayre->StoredProcedure->Table在应用程序表单中,我创建了 middleLayer 的对象并在中间层的 Insert/update/delete 函数中传递数据.我正在工厂类中创建 sqlcommand 的对象并填充我从中间层获取的数据并将该对象 os sqlcommand 传递给 DAL.
I am developing application in N-Tier Architecture. as we all know that we need to implement transactions while insert/update/delete operation. please tell me how to use transaction in c#.net in N-Tier architecture. my architecture is like this Applicationform->middle_Layre->Factory->DataAccessLayre->StoredProcedure->Table in application form i create object of middleLayer and pass data in Insert/update/delete function of middle layer. i am creating object of sqlcommand in factoryclass and fill the data which i gets from middle layer and pass that object os sqlcommand to DAL.
推荐答案
以下是您可以遵循的代表性软件层模式:
Here is a representative pattern of software layers you can follow:
Database <-> DAL <-> Repository <-> BLL <-> Controller <-> View Model <-> UI
哪里
DAL == Data Access Layer (aka ORM, Object-Relational mapper)
BLL == Business Logic Layer*
在此模型中,事务发生在存储库中,其中安排了工作单元".通常,这是通过从 DAL 请求数据、对其执行工作并保存更改来实现的.DAL 通常会围绕您的工作单元进行事务处理.
In this model, the transaction takes place in the Repository, where a "unit of work" is arranged. Typically, this happens by requesting data from the DAL, performing work on it, and saving changes. The DAL will generally wrap a transaction around your unit of work.
数据库、DAL、存储库和 BLL 共同构成了所谓的 MVC(模型-视图-控制器)架构中的模型.所有业务逻辑和数据操作都发生在模型中.控制器充当模型和视图模型/UI 之间的中间人,它们共同形成视图.
The Database, DAL, Repository and BLL collectively form what is known as the Model in MVC (Model-view-controller) architecture. All business logic and data manipulation takes place in the Model. The controller acts as a go-between between the model and the View Model/UI, which collectively form the view.
存储库是您设置工作单元"的地方.
The Repository is where you would set up your "Unit of Work."
*可选
这篇关于如何在 N 层架构中维护事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!