泛型方法

 

===BLL=========================================

public IList<ItemInfo> GetItemsByProduct(string productId) {

   // Validate input
   if(string.IsNullOrEmpty(productId))
    return new List<ItemInfo>();

   // Use the dal to search by productId
   return dal.GetItemsByProduct(productId);
  }

 

====DAL===========================================


  public IList<ItemInfo> GetItemsByProduct(string productId) {

            IList<ItemInfo> itemsByProduct = new List<ItemInfo>();

            SqlParameter parm = new SqlParameter(PARM_PRODUCT_ID, SqlDbType.VarChar, 10);
            parm.Value = productId;

   using(SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_ITEMS_BY_PRODUCT, parm)) {
                while (rdr.Read()) {
                    ItemInfo item = new ItemInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetInt32(2), rdr.GetDecimal(3), rdr.GetString(4), rdr.GetString(5), rdr.GetString(6), rdr.GetString(7));
                    itemsByProduct.Add(item);
                }
            }
            return itemsByProduct;
        }

=====================================================

你可能感兴趣的:(泛型方法)