我有一个被调用的对象Product,我想从所有产品列表中检索某个产品的"物料清单"(存储在SQL Server中).我应该先创建Product对象,然后通过方法从我的存储库中获取数据,如下所示:
var productId = "1";
Product product = new Product(productId);
DataTable billOfMaterial = product.GetBillOfMaterial();
Run Code Online (Sandbox Code Playgroud)
或者从静态存储库检索数据strait,如下所示:
var productId = "1";
DataTable billOfMaterial = product.GetBillOfMaterial(productId);
Run Code Online (Sandbox Code Playgroud)
或者可能是这样的?
var productId = "1";
DataTable BillOfMaterial = ProductRepository.GetBillOfMaterial(productId);
Run Code Online (Sandbox Code Playgroud)
或者也许当我创建产品时,我会自动在产品的构造函数中获取Bill:
var productId = "1";
Product product = new Product(productId);
DataGrid.DataSource = product.BillOfMaterial;
Run Code Online (Sandbox Code Playgroud)
我正在使用MVP模式,并且不知道最佳做法是填充对象只是为了获得DataTable或者我是否可以快速使用静态存储库.这样做的正确方法是什么?