title: Using entity framework with custom subclasses
body: <p>I am using the C# entity framework to map data to sql server for a project. I am trying to figure a way to use the entity framework to automatically produce custom subclasses based on a discriminator field while not requiring the sub classed entities to have tables. </p>
  
  <p>Example:</p>
  
  <p>In entity framework I have a object <code>A</code> which has a field <code>type</code>. I also have the following</p>
  
  <pre><code>public class B : A {
  }
  
  public class C : A {
  }
  </code></pre>
  
  <p>I am looking for a way to make entity framework recognize that the <code>type</code> field is for example <code>B</code> and then create an instance of the <code>B</code> class. The classes have no data that needs to be persisted to the database. They are just wrappers for rows in a different table.</p>
  
  <p>Example:</p>
  
  <p>I have a table of item objects. Each item object has a collection of item settings and an item type field.</p>
  
  <p>There are different types of items (Text, Radio, Checkbox) and they are all rendered differently using an abstract <code>render()</code> method. Each of these subtypes also has a certain set of item settings that are required for that object.</p>
  
  <p>If I could create entity subclasses without having to map them to a database I could have a TextItem be a subclass of Item, implement my <code>render()</code> method and the add properties that map to each of the values in my item settings table. Then when im pulling a new item from the database, based on the type field it would create my specific class automatically based on a discriminator. </p>
  
  <p>I have done this sort of thing using DBML. I would like to use the entity framework as it is more powerful, but there may not be a way to do what i'm looking for.</p>