title: Entity framework code first map multiple complex types of the same type to a table
body: <p>If you have the following domain model:</p>
  
  <pre><code>public class Test
  {
      public string Description { get; set; }
  
      public TestB A { get; set; }
      public TestB B { get; set; }
      public TestB C { get; set; }
  
  }
  
  public class TestB
  {
      public string Name { get; set; }
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>And you have a table with the following structure:</p>
  
  <pre><code>Test
   - Description
   - NameA
   - DescriptionA
   - NameB
   - DescriptionB
   - NameC
   - DescriptionC
  </code></pre>
  
  <p>Where the name and description pairs map to an individual instance of complex type B. </p>
  
  <p>Is there any way of defining this mapping purely using the fluent APIs assuming the database schema cannot be changed?</p>
  
  <p>The only way I have gotten this to work in a reasonable way is to derive subtypes of TestB and map them like this:</p>
  
  <pre><code>        modelBuilder.ComplexType&lt;TestB&gt;().Property(x =&gt; x.Name).HasColumnName("NameA");
          modelBuilder.ComplexType&lt;TestB&gt;().Property(x =&gt; x.Description).HasColumnName("DescriptionA");
  
          modelBuilder.ComplexType&lt;TestB1&gt;().Property(x =&gt; x.Name).HasColumnName("NameB");
          modelBuilder.ComplexType&lt;TestB1&gt;().Property(x =&gt; x.Description).HasColumnName("DescriptionB");
  </code></pre>
  
  <p>I'd rather not have to define derived types purely for the mappings to entity framework. </p>