title: Object oriented database models
body: <p><strong>UPDATED WITH CODE!</strong></p>
  <p>I am developing a web application using ASP.NET MVC 3 and I want to create an object-oriented list using &quot;ADO.NET Entity Data Model&quot;.</p>
  <p>I've created models by entity framework &quot;Code-First&quot; using &quot;ADO.NET Entity Data Model&quot; and then
  generated a database. Afterward I have generated an entire DAL using &quot;Reverse
  engineer Code First&quot; from the database that contains my classes plus &quot;DataContext&quot; object.</p>
  <p>I have a simple type called &quot;Item&quot;, contain &quot;Name&quot; property.
  In addition, there are some derived types such as &quot;Weapon&quot; and &quot;Armour&quot;, containing exclusive properties such as &quot;Damage&quot; and &quot;Defense&quot; respectively.</p>
  <p>As a common object-oriented way, <strong>I want to iterate over the Items being able to see the exclusive properties of each type.</strong></p>
  <p>This is my purpose, being able to iterate over all the items a player has, including their properties, Even though they are derived from Item:</p>
  <pre><code>        // Creating a game context that derives from DbContext
          GameContext context = new GameContext();
  
          // Take my profile
          Player me = context.Players.First();
  
          // Get my items and show them, show both 
          var myItems = me.Items;
  
          // Printing all the items that I have with the properties of the derrived objects as well
          // (&quot;Weapon&quot; and &quot;Armour&quot; objects as well (They derive from &quot;Item&quot; object)
          foreach (var item in myItems)
          {
              // Accessing the item's name. every item has this property, so there is nothing special.
              Console.WriteLine(&quot;Name:&quot; + item.ItemName);
  
              if (item.Type == &quot;Weapon&quot;)
              {
                  // Accessing the item's damage, which is uniqe to a weapon (that derrives from &quot;Item&quot; object).
                  Console.WriteLine(&quot;Damage:&quot; + (Weapon)item.ItemDamage);
              }
  
              if (item.Type == &quot;Armour&quot;)
              {
                  // Accessing the item's defense, which is uniqe to an armour (that derrives from &quot;Item&quot; object).
                  Console.WriteLine(&quot;Defense:&quot; + (Armour)item.ItemDefense);
              }
          }
  </code></pre>
  <p>From now further this is what I have and I am not satisfied with, even though I think this is unnecessary.</p>
  <p>My current model relations (That I am not satisfied with):
  <img src="https://i.stack.imgur.com/Qwft6.png" alt="These are my models created in a &quot;ADO.NET Entity Data Model&quot;" /></p>
  <p>Item base class that contain the different items, NOTE that the use of an &quot;Item&quot; object is just like the use of an abstract class - It only going to be used by its derived classes - &quot;Weapon&quot;, &quot;Armour&quot;, &quot;Jewelry&quot; and so on.</p>
  <p>Weapon which contain a navigation property the appropriate item, plus its own properties (Damage in this case).</p>
  <p>ConcrateItem is an item that a player has. which means its contains a navigation property (being used just like pointer) to that item, plus the number of upgrades that this instance of item was upgraded, since it is individually per item and not shared among all the items of this kind.</p>
  <p>What I've done at first was to link the weapon and armour types to the appropriate item
  type, so I can access the item base properties if i iterate over the Weapons table or over the Armour table, but the problem is that <strong>I Want to iterate over all items at once and from this point to be able to get an exclusive properties</strong> and not to iterate over every table that contains a specific class derived from Item.</p>
  <p>Does anyone know how can I achieve that?</p>