小编goo*_*454的帖子

实现存储库模式的正确方法是什么?以及如何使用它?

我有一个被调用的对象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或者我是否可以快速使用静态存储库.这样做的正确方法是什么?

c# mvp design-patterns repository-pattern

1
推荐指数
1
解决办法
137
查看次数

标签 统计

c# ×1

design-patterns ×1

mvp ×1

repository-pattern ×1