Last post Dec 28, 2010 10:58 AM by sakib_cse
Dec 25, 2010 08:10 AM|sakib_cse|LINK
recently i've studied on ADO.NET's Entity Model Framework and say 'wow' as ORM is one of the fevourite pattern i practice..but suddenly i've come to an ambiguous situation when i'm going to start....
i usually follow the following 3-tier architecture..
1. UI Layer
2. BLL - business logic layer
3. DAL - Data Access Layer
a. DTO / DAO
b. Gateway (contains the sql query/stored procedure and connection with DB)
now when i'm going to use the Entity Model Design,where the DBML/ .edmx File should be placed !?!!!
Because many a times i'm using the DBML file as DTO because of the mapped objects.. in the same time, sometimes DBML ( .edmx file in .NET 4.0) contains CRUD methods and stored procedured method as well as methods with different selection operations,- which
should be in Gateway......
so where the .edmx file should be placed !?!! IN DTO namespace !? or in Gateway namespace !!!
moreover sometimes there is no need for the BLL which breaks the rules of inter-layer-communication (UI > BLL > DAL.Gateway) .. !!!
what makes me confuse is, what should be the ideal n-tier architecture when i'll use the ADO.NET Entity Model Design Framework...
N - Tier
Entitiesy Model Design Framework
Dec 25, 2010 11:48 PM|ignatandrei|LINK
where the .edmx file should be placed !?!! IN DTO namespace !? or in Gateway namespace !!!
Dec 27, 2010 12:56 PM|sakib_cse|LINK
but doesn't it break the layer !!
like in UI when i need to use DTO object, i'm calling Entities from Gateway which is Data Access Layer... UI should to be interact with Business Logic Layer where information passes through DTO .. not DAL where gateway or CRUD information lays ... BLL should
interact with DAL
Dec 27, 2010 03:11 PM|ignatandrei|LINK
ok. Think about a simple application with 2 Entities : Employee -Department ( a department have many employees)
How do you think in layers?
Dec 28, 2010 10:58 AM|sakib_cse|LINK
well consider i am working in a single Tier and using 3 Layer architechture.
i want to add new employee....
1st i'll make two DTO classes
public class Employee
public int Id;
public string Name;
public int DepartmentId;
public class Department
public string Id;
public int Name;
in the UI, i will make a form with text box to input employee name and a dropdown which will select existing department.
1st i've to get department list from DB.. UI will call DepartmentManager which is in BLL layer..
so in UI i'll call:
DeparmentManager manager = new DepartmentManager();
dropDownList1.DataSource = departments;
where DepartmentManager is:
public class DepartmentManager
public List<Department> GetDepartments()
DepartmentGateway gateway = new DepartmentGateway();
// if there is any Business logic regarding to this function, i will implement here and then retrun to UI
public class GetDepartments
public List<Department> GetDepartments()
List<Department> departments = new List<Departments>();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
// set sql connections and command
foreach(DataRow row in dt.Rows)
Department department = new Department();
department.Name = row["Name"].ToString();
same way when i will go through UI--> BLL ( EmployeeManager ) ----> DAL.Gateway ( EmployeeGateway )
you see, I'm using Department class as DTO which is transfering Data over the layers.. but if i want to use EF, and place the EF in gateway layer, then in UI Layer I should not get that .edmx file as BLL is the next layer to UI. again if i can not access
the .edmx file then how do i get 'Department' class as in table mapped object classes are there!
so if i've access the table-object classes then from UI i have to call Gateway (as i've placed the .edmx file in Gateway layer), which is violation for Layer architecture! (as a layer should interact with its conjugant layers).
one one thing left; if i place the .edmx file in DTO. but by doing so, i'm giving UI Layer all the access of DTO objects (here Department) as well as the CRUD methods which are automatically built in .edmx file ( say , myContext.AddToDepartments() ) which
should be accessed only by BLL or DAL ...
:-s i'm a bad explainer.. may be i couldn't make you understand my confusion :-s