数据集的替代方法是在3层架构中在dal和bal之间传递多个值的行? [英] What is the alternative for dataset to pass rows of multiple values between dal to bal in 3 tier acrchitecture ?

查看:122
本文介绍了数据集的替代方法是在3层架构中在dal和bal之间传递多个值的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中的c#ado.net中编写3层代码

在DAL中,我在数据集中获取sql表值

我听说过将数据集从DAL传递到BAL和BAL到表示层是不可取的,考虑到应用程序在网络带宽使用方面的性能

数据集的替代方案是什么?

我尝试过:

在Dal中使用数据集作为返回类型的创建方法

解决方案

只获取前端绑定所需的数据,可以在Sql Query / Sp端完成。



在DAL层中,您从数据库中获取数据并填写数据集。您可以将数据集返回到BAL图层。在BAL层中,如果要实现某些业务逻辑,则可以在那里实现。


在BAL中编写代码的行业范围实践是从DAL中正确定义对象。让我通过一个例子向你解释上面的一个班轮。



假设你要返回一个数据集,其中包含一个包含汽车记录的数据表。每条记录代表一辆汽车,上面有模型,必和必拓,类型。

<前lang =SQL> 模型|必和必拓| 类型
雷克萨斯| 250 |轿车
美洲虎| 600 |轿车
丰田| 550 | SUV



如果您分析上述数据,您会看到每一行都是一个代表汽车的对象。所以你可以上课说:

  public   class  Car 
{
public string 模型{获得; set ;}
public int BHP { get ; set ; }
public string 输入{ get ; set ; }
}



现在,您可以将每一行填充到上面的Car对象中,将整个表填入 IEnumerable< Car>



通过遵循上述方法,您可以完全依赖于对象,并且可以避免在BAL和其他更高层中使用数据集/数据表-Tier应用程序。



实现上述转换的最简单方法是在DAL中创建一个对象映射器,它将转换你的 DataTable 进入 IEnumerable< Car> 对象并将其返回到您的BAL


I am writing 3 tier code in c# ado.net in asp.net

In DAL i am fetching sql table values in dataset

I have heard that passing dataset from DAL to BAL and BAL to presentation layer is not advisable taking into consideration the application's performance with regards to network bandwidth usage

What is the alternative to dataset ?

What I have tried:

Created method with dataset as return type in Dal

解决方案

Fetch only those data which is required for binding in front end and that can be done in Sql Query / Sp side.

In you DAL layer you are fetching the data from DB and fill in Dataset. You can return the dataset to your BAL layer. In the BAL layer if you want to implement some business logic then you can implement there.


The industry wide practice for writing code in BAL is to have properly defined objects from DAL. Let me explain you the above one liner with an example.

Let say you are returning a dataset having a datatable containing records of cars. Each record represent a car with fields say Model, BHP, Type.

Model | BHP | Type
Lexus | 250 | Sedan
Jaguar| 600 | Sedan
Toyota| 550 | SUV


If you analyse the above data you would see that each row is an object representing a car. So you can make a class say:

public class Car
{
   public string Model { get; set;}
   public int BHP { get; set; }
   public string Type { get; set; }
}


Now, you can fill each row into the above Car object and the entire table into IEnumerable<Car>

By following the above approach, you can work purely on objects and you can avoid using Datasets/datatables in your BAL and other higher layers on n-Tier applications.

The easiest way to achieve the above transformation is by creating an object mapper in DAL which would convert your DataTable into IEnumerable<Car> object and return it to your BAL


这篇关于数据集的替代方法是在3层架构中在dal和bal之间传递多个值的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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