0

I am designing a WCF service that has several functions:

1.  ProductDTO         GetProduct ( Guid productId )
2.  void               SetProduct ( ProductDTO product )
3.  List<ProductDTO>   GetAllProducts()
4.  void               SetAllProductValues ( int newValue )

These are the operations the Service will support. I will have a Business Layer (BL) and a Data-Access Layer (DAL).

I will be using LINQ-TO-EF as my ORM to connect to the SQL server tables.

My question is - what exactly should the DAL contain ?

I am asking this question because I have read 2 different books saying different things:

First Approach: the DAL contains only classes needed for data-access layer (if at all). It includes special entities or functions for that. The EDMX and model file for the LINQ-TO-EF is in a seperate assembly (that is referenced by the BL and the Service Layer). In this method - the BL contains the actual functions that perform the LINQ queries. For example : 'GetProduct' will perform the LINQ query to extract data from the DB. So - in this approach - what exactly is supposed to be in the DAL ? Is it empty ?

Second Approach: the DAL contains functions for performing CRUD operations on the DB, meaning - any LINQ-TO-EF queries will be done in the DAL. So - in this approach - what exactly does the BL do except for maybe some validations ?

Which approach is the correct one and how does that answer my concern of that approach ?

John Miner
  • 893
  • 1
  • 15
  • 32

1 Answers1

0

From MSDN:

"All code that is specific to the underlying data source – such as creating a connection to the database, issuing SELECT, INSERT, UPDATE, and DELETE commands, and so on – should be located in the DAL. The presentation layer should not contain any references to such data access code, but should instead make calls into the DAL for any and all data requests. Data Access Layers typically contain methods for accessing the underlying database data. The Northwind database, for example, has Products and Categories tables that record the products for sale and the categories to which they belong. In our DAL we will have methods like:

GetCategories(), which will return information about all of the categories

GetProducts(), which will return information about all of the products

GetProductsByCategoryID(categoryID), which will return all products that belong to a specified category

GetProductByProductID(productID), which will return information about a particular product"

Of course you are always free to choose your own design, but I like to stick with generally accepted practices so my code will likely be acceptable in any shop and understandable to anyone that has to maintain it later...

CodeChops
  • 1,980
  • 1
  • 20
  • 27