title: How to read dynamic properties from database
body: <p>I will try to explain my scenario the best way I can. I have the following tables in my database:</p>
  
  <pre><code>Products{ProductId, CategoryId ...}
  Categories{CategoryId ...}
  CategoryProperties{CategoryPropertyId, CategoryId, Name ...}
  PropertyValues{ProductId, CategoryPropertyId, Value ...}
  </code></pre>
  
  <p>So the goal is to have list of products which belongs to some category and each category can have 'n' number of properties with values in the 'PropertyValues' table. I have a query that returns data based on 'categoryId' so I can always get different results from the database:</p>
  
  <p>For the CPU category:</p>
  
  <pre><code>intel i7 | CPU | Model | Socket | L1 Cash | L2 Cahs | etc.
  </code></pre>
  
  <p>For the HDD category:</p>
  
  <pre><code>samsung F3 | HDD | Model | Speed | GB | etc.
  </code></pre>
  
  <p>So based on categories from my query as a result I always can get different column numbers and names. For database access I use simple ADO.NET call to stored procedure that return result.
  But because query result is dynamic in it's nature I don't know what is a good way to read this data.</p>
  
  <p>I made a <code>Product</code> entity but <strong>I am confused how to make it really :(</strong>
  I thought that I can make a <code>Product</code> entity and make other entities which <strong>inherit</strong> <code>Product</code> like <code>Cpu</code>, <code>Hdd</code>, <code>Camera</code>, <code>PcCase</code>, <code>GraphicCard</code>, <code>MobilePhone</code>, <code>Gps</code> etc. <br/><br/>but I think <strong>that it's stupid</strong> because I can end this with <strong>200+ entities</strong> in domain.
  <br/><br/>
  What would you do in this situation?<br/>
  How to read and where to put this <strong>dynamic properties</strong>?
  <br/><br/>
  <strong>UPDATE - some solution</strong>
  <br/><br/>
  All right based on <em>@millimoose</em> suggestion for <code>Dictionary</code> and <em>@Tim Schmelter</em> idea to use <code>DataTable</code> object I came to some solution.<br/>
  Now... this works I get data read them and I can display them.<br/>
  But I still need advice from smarter people than me on <strong>am I did this good</strong> or should I handle this better or I am made some <strong>spageti code</strong>.
  So here what I did:</p>
  
  <pre><code>public class Product
      {
          public Product()
          {
              this.DynamicProperties = new List&lt;Dictionary&lt;string, string&gt;&gt;();
          }
  
          public List&lt;Dictionary&lt;string, string&gt;&gt; DynamicProperties { get; set; }
  
      }
  ...
  List&lt;Product&gt; products = new List&lt;Product&gt;();
  ...
  using (SqlDataAdapter a = new SqlDataAdapter(cmd))
                  {
                      DataTable t = new DataTable();
                      a.Fill(t);
  
                      Product p = null;
  
                      foreach (DataRow row in t.Rows)
                      {
                          p = new Product();
                          foreach (DataColumn col in t.Columns)
                          {
                              string property = col.ColumnName.ToString();
                              string propertyValue = row[col.ColumnName].ToString();
  
                              Dictionary&lt;string, string&gt; dictionary = new Dictionary&lt;string, string&gt;();
  
                              dictionary.Add(property, propertyValue);
  
                              p.DynamicProperties.Add(dictionary);
                          }
  
                          products.Add(p);
                      }
                  }
  </code></pre>