Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 7-Apr-17 6:54am
v4

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.
 
Share this answer
 
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.
SQL
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:
C#
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900