所以我必須從將返回所有在我的商店,並與該產品相關的部門ID的產品數據庫中的兩列。創建字典或IEnumerable的對象
我想要做的是使用list/dictionary/ienumerable集創建一些東西,這樣如果我給一個產品id的函數,它會吐出部門id。目前我遇到了一些麻煩,導致申報正確,需要該部門的幫助。
首先我對產品和類別之間的關係的基礎。然後,我想ProductCategoryCollection
返回每個產品和類別/部門的所有映射的集合。我陷入了第二部分,並不確定從哪裏去。
helper.GetProductToCategoryMatching()
從數據庫返回的行。
public class ProductAndCategoryID
{
public ProductAndCategoryID(int product, int category)
{
this.productID = product;
this.categoryID = category;
}
public int productID;
public int categoryID;
}
public class ProductCategoryCollection : IEnumerable<ProductAndCategoryID>
{
public ProductCategoryCollection()
{
}
public List<ProductCategoryCollection> populate()
{
ShippingClassHelper helper = new ShippingClassHelper();
DataSet ds = new DataSet();
List<ProductCategoryCollection> list = new List<ProductCategoryCollection>();
ds = helper.GetProductToCategoryMatching();
foreach (DataRow row in ds.Tables[0].Rows)
{
}
return new List<ProductCategoryCollection>();
}
}
這個我試過前面但我不能設置'ProductAndCategoryID'的值,或者我想如果我只是從數據庫返回兩行,我需要嗎? –
返回的表是什麼樣的? – Jeremy
'ProductID'具有對應關係的'CategoryID'。因此產品#660在類別137中,將返回'660' | '137' –