Exemple #1
0
 // use ordinals to speed up access to DataReader
 // links:
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, ProductHistoryDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.ProductId))
     {
         ProductId = reader.GetGuid(ordinals.ProductId);
     }
     if (!reader.IsDBNull(ordinals.ProductName))
     {
         ProductName = reader.GetString(ordinals.ProductName);
     }
     if (!reader.IsDBNull(ordinals.StateName))
     {
         StateName = reader.GetString(ordinals.StateName);
     }
     if (!reader.IsDBNull(ordinals.DateTime))
     {
         DateTime = reader.GetDateTime(ordinals.DateTime);
     }
     if (!reader.IsDBNull(ordinals.UserName))
     {
         UserName = reader.GetString(ordinals.UserName);
     }
     if (!reader.IsDBNull(ordinals.ProductBecameId))
     {
         ProductBecameId = reader.GetGuid(ordinals.ProductBecameId);
     }
 }
Exemple #2
0
        /// <summary>Get product history</summary>
        /// <cardinality>Many</cardinality>
        public List <ProductHistoryData> ProductHistory(
            Guid productId
            )
        {
            var ret = new List <ProductHistoryData>();

            string sql = @" 
                    select 
	                     p.product_id
	                    ,p.product_name
	                    ,sr.default_state_name  as state_name
	                    ,p.date_time
	                    ,u.default_user_name    as user_name
	                    ,p.product_became_id
                    from product                    as p
                    inner join default_user         as u    on u.default_user_id = p.user_id
                    inner join default_state_ref    as sr	on sr.default_state_rcd = p.state_rcd
                    where p.product_id = @product_id
                    order by p.date_time
                ";

            using (var conn = new SqlConnection(ConfigurationManager.AppSettings["Conn"])) {
                conn.Open();

                using (var command = new SqlCommand(sql, conn)) {
                    command.Parameters.Add("@product_id", SqlDbType.UniqueIdentifier).Value = productId;

                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    var ordinals = new ProductHistoryDataOrdinals(reader);

                    while (reader.Read())
                    {
                        var data = new ProductHistoryData();
                        data.Populate(reader, ordinals);
                        ret.Add(data);
                    }

                    reader.Close();
                }

                return(ret);
            }
        }