Best Practice (Keeping it simple) to wrap a method returning List of Products from DAL to BLL
Below is a method from from my console application calling a DAL method. Whats the best way to wrap this in a BLL method so it can be called directly from the presentation? I have worked on projects in the past where we called everything from the DAL such as below, however would nt it be best to get everything from BLL?
public static void getAllProducts(int ID)
{
List<Product> productList = new List<Product>();
ProductDA productDA = new ProductDA();
productList = productDA.GetAllProducts(ID);
foreach (Product product in productList)
{
Console.WriteLine(" ProductID:" + pr开发者_如何转开发oduct.ProductID);
Console.WriteLine(" Product Name:" + product.ProductName);
Console.WriteLine(" Product Date:" + product.ProductDate);
}
}
If most of the project gets the data from Stored Procedures already built and in Production that work fine, would it be best to just refrence the DAL rather than double wrap things in a BLL?
The best way is not at all.
- It should be a Get method that is IQueryable.
Then you would expose it through a repository service in the business layer that... has Get : IQueryable again.
THis would allow users to write:
Get ().Where (x=> x.ProductId= 223 || x.ProductName.StartsWith ("someproduct")).
Flexible.
精彩评论