开发者

Best Practice (Keeping it simple) to wrap a method returning List of Products from DAL to BLL

开发者 https://www.devze.com 2023-02-06 16:22 出处:网络
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 i

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号