- , - .
, , , , -.
BLL ( ) , DTO.
http://martinfowler.com/bliki/AnemicDomainModel.html
ProductBLL productBll = new ProductBLL();
List<ProductDTO> productList = productBll.GetAllProducts();
, , DTO - ( - ).
<Product>
s, BLL DTO - . . , , . , , , , , .
BLL -. DTO - DAL. , DTO, - .
, , DTO, DAL , , datareader . DAL , .
, :
public class Product {
private Product(IDataRecord dr) {
}
static private List<Product> GetList(string sp, Action<DbCommand> addParameters) {
List<Product> lp = new List<Product>();
foreach (var dr in DAL.Retrieve(sp, addParameters) ) {
lp.Add(new Product(dr));
}
return lp;
}
static public List<Product> AllProducts() {
return GetList("sp_AllProducts", null) ;
}
static public List<Product> AllProductsStartingWith(string str) {
return GetList("sp_AllProductsStartingWith", cm => cm.Parameters.Add("StartsWith", str)) ;
}
static public List<Product> AllProductsOnOrder(Order o) {
return GetList("sp_AllProductsOnOrder", cm => cm.Parameters.Add("OrderId", o.OrderId)) ;
}
}
DAL. DataRecords DTO, - .
DAL.Retrieve SqlServer, ( , CommandText); , (, , ):
public static IEnumerable<IDataRecord> SqlRetrieve(string ConnectionString, string StoredProcName,
Action<SqlCommand> addParameters)
{
using (var cn = new SqlConnection(ConnectionString))
using (var cmd = new SqlCommand(StoredProcName, cn))
{
cn.Open();
cmd.CommandType = CommandType.StoredProcedure;
if (addParameters != null)
{
addParameters(cmd);
}
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
yield return rdr;
}
}
}
.