三层应用程序数据访问层 [英] Three tier application data access layer

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

问题描述

我正在基于Windows的c#应用程序开发3层应用程序。



我想在Dal中创建一个常用方法,用于执行dml操作,如使用ado.net进行插入,更新,删除,而不是使用工厂类方法,即泛型Dal。 br />


以下是我方法的示例结构:



// DTO是数据传输对象或实体层将值传递给DAL



  public  字符串 AddUpdDel(DTO objdto)
{

}





我怎么做到这一点?



我尝试过:



public string AddUpdDel(DTO objdto)

{



}

解决方案

传递一些变量作为操作指示器。

即是否要添加或删除或更新,并根据变量执行操作块可能正在使用if else或switch。


< BLOCKQUOTE>


有几种方法可以达到这个目的。如果我没有错,你试图使用一种方法使用ADO.NET进行插入,更新和删除。我会建议你两种方式。



1.)创建一个方法,你将拥有与数据库的ADO.NET连接。在该方法中,您可以使用switch case语句来隔离查询以进行插入,更新和删除操作。



2.)保留一个参数/变量以指示类型您尝试执行的操作,并将该变量作为参数传递给存储过程。在存储过程中,您可以使用case语句和相应的查询来将其与不同的操作分开。



无论哪种方式,您都可以实现您正在尝试的目标实现。如果您有任何疑问,请告诉我。



谢谢,

Sisir Patro


I am developing 3 tier application in windows based c# application.

I want to create a common method in Dal for performing dml operations like insert, update, delete using ado.net and not using factory classes approach i.e. generic Dal.

Following is sample structure of my method:

// DTO is data transfer object or entity layer for passing values to DAL

public string AddUpdDel(DTO objdto) 
{

}



How would I achieve it ?

What I have tried:

public string AddUpdDel(DTO objdto)
{

}

解决方案

pass some variable as operation indicator.
i.e. whether you want to add or delete or update and depending upon variable execute that operational block may be using if else or switch.


Hi,

there are several ways to achieve this. If I am not wrong you are trying to use one method for insert, update and delete using ADO.NET. I will suggest you 2 ways.

1.) Create a method where you will be having the ADO.NET connection to the database. In the method you can use switch case statement to segregate your queries for Insert, Update and Delete operation.

2.) Keep a parameter/variable to indicate the type of operation you are trying to perform and pass that variable as a parameter to a stored procedure. In the stored procedure you can have the case statement and respective queries to get it be segregated from different operations.

In either way you can achieve the goal that you are trying to achieve. If you have any queries please let me know.

Thanks,
Sisir Patro


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

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