title: SQLException: Invalid column name
body: <p>I have recently converted my existing database to code using EF Reverse Engineer Code First. After polishing most of the results, I've started writing tests. The error I'm currently having is trying to access a column name called 'Element_ElementCode', however no such column exists.<br>
  To be sure of this, I've performed a search on my entire project to avoid the possibility of accidentally declaring it as such.</p>
  
  <pre><code>Find all "Element_ElementCode", Subfolders, Find Results 1, Entire Solution, ""
  Matching lines: 0    Matching files: 0    Total files searched: 120
  </code></pre>
  
  <p>The exact error is as follows:</p>
  
  <pre><code>System.Data.SqlClient.SqlException: Invalid column name 'Element_ElementCode'.
  </code></pre>
  
  <p>Invalid column name 'Element_ElementCode' is repeated 10-15 times and the stacktrace doesn't provide any clue.</p>
  
  <p>This exception occurs when executing a test which contains an expression to retrieve data and performs some asserts onto it.</p>
  
  <pre><code>var doos = (dbContext.Elementen.Where(d =&gt; d.ElementCode == "DOOS9001")).FirstOrDefault();
  </code></pre>
  
  <p>This is the result from a query in SQL Server itself:
  <img src="https://i.stack.imgur.com/1WsM2.jpg" alt="enter image description here"></p>
  
  <p><code>Element</code> (inside <code>Element.cs</code>) has the following fields:</p>
  
  <pre><code>ElementCode
  Doelgroep
  Type
  Omschrijving
  Titel
  </code></pre>
  
  <p>Elements are mapped like this:</p>
  
  <pre><code>public class ElementenMap : EntityTypeConfiguration&lt;Element&gt; {
          public ElementenMap() {
  
              // Primary Key
              this.HasKey(t =&gt; t.ElementCode);
  
              // Properties
              this.Property(t =&gt; t.ElementCode)
                  .IsRequired()
                  .HasMaxLength(255);
  
              this.Property(t =&gt; t.Type)
                  .HasMaxLength(31);
  
              this.Property(t =&gt; t.Doelgroep)
                  .HasMaxLength(255);
  
              this.Property(t =&gt; t.Omschrijving)
                  .HasMaxLength(255);
  
              this.Property(t =&gt; t.Titel)
                  .HasMaxLength(255);
  
              // Table &amp; Column Mappings
              this.ToTable("Elementen");
              this.Property(t =&gt; t.ElementCode).HasColumnName("ElementCode");
              this.Property(t =&gt; t.Type).HasColumnName("Type");
              this.Property(t =&gt; t.Doelgroep).HasColumnName("Doelgroep");
              this.Property(t =&gt; t.Omschrijving).HasColumnName("Omschrijving");
              this.Property(t =&gt; t.Titel).HasColumnName("Titel");
  
              // Relationships
              this.HasMany(t =&gt; t.Kernwoorden)
                  .WithRequired(t =&gt; t.Element)
                  .Map(m =&gt; m.ToTable("Kernwoorden"));
          }
      }
  </code></pre>
  
  <p>Furthermore: I am certain the database is accessed because other tests on different tables inside the same database succeed.</p>
  
  <p>I've tried to provide as much relevant info as possible, let me know if I've forgotten a source. Why is it trying to access a column called <code>Element_ElementCode</code>? Is it perhaps a convention I've forgotten to turn off (I've already had to turn off the PluralizingTableNameConvention)?</p>
  
  <p>What direction should I be looking for this?</p>
  
  <p>Edit:  </p>
  
  <p><strong>Kernwoord.cs</strong></p>
  
  <pre><code>public class Kernwoord {
          public string ElementCode { get; set; }
  
          public string KernwoordString { get; set; }
  
          public virtual Element Element { get; set; }
      }
  </code></pre>
  
  <p><strong>Element.cs</strong></p>
  
  <pre><code>public partial class Element {
          public Element() {
              this.LeertrajectElementen = new List&lt;LeertrajectElement&gt;();
              this.Kernwoorden = new List&lt;Kernwoord&gt;();
          }
  
          public string ElementCode { get; set; }
  
          public string Type { get; set; }
  
          public string Doelgroep { get; set; }
  
          public string Omschrijving { get; set; }
  
          public string Titel { get; set; }
  
          public virtual Casus Casus { get; set; }
  
          public virtual Document Document { get; set; }
  
          public virtual Doos Doos { get; set; }
  
          public virtual ICollection&lt;LeertrajectElement&gt; LeertrajectElementen { get; set; }
  
          public virtual StellingenSpel StellingenSpel { get; set; }
  
          public virtual ICollection&lt;Kernwoord&gt; Kernwoorden { get; set; }
      }
  </code></pre>
  
  <p><strong>LeertrajectElementenMap.cs snippet:</strong></p>
  
  <pre><code> this.HasRequired(t =&gt; t.Element)
       .WithMany(t =&gt; t.LeertrajectElementen)
       .HasForeignKey(d =&gt; d.ElementCode);
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>The problem was solved by fixing the existing inheritance issues.</p>