title: EF/Code First Migration - implicit table mappings?
body: <p>I am using a code first migration approach to creating new tables in an existing database, and I'd like to know if this is auto-creating a property-to-field mapping somewhere in the project.</p>
  
  <p>For example: the "Category" table pre-existed in the database. It was created directly in SQL, and my MCV project has a CategoryMap.cs file that explicitly maps the Category entity properties to the Category table fields:</p>
  
  <p><strong>CategoryMap.cs</strong></p>
  
  <pre><code>this.ToTable("Category", "ctt");
  this.Property(t =&gt; t.Id).HasColumnName("Id");
  this.Property(t =&gt; t.ClientId).HasColumnName("ClientId");
  this.Property(t =&gt; t.CategoryTypeId).HasColumnName("CategoryTypeId");
  etc.
  </code></pre>
  
  <p>The db context class explicitly points to this mapping in the OnModelCreating method:</p>
  
  <pre><code>    protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
  
          modelBuilder.Configurations.Add(new CategoryMap());
  etc.
  </code></pre>
  
  <p>With this set-up, I can save data to the Category table, as long as I keep the mapping pieces in place.</p>
  
  <p>On the other hand, I've created a new table using the code first approach:</p>
  
  <p>1) Create a "MyTable" entity class</p>
  
  <p>2) Add this code to my context class:</p>
  
  <pre><code>public DbSet&lt;MyTable&gt; MyTable { get; set; }
  </code></pre>
  
  <p>3) Run the add-migration and update-database commands</p>
  
  <p>That created a "MyTable" table in the database schema, and I can save data to this table, despite the fact that there is no mapping file, and no explicit mapping code in the OnModelCreating method of my db context class.</p>
  
  <p>Now, if I comment out the "modelBuilder.Configurations.Add(new CategoryMap());" line of code in the context class, I can't save data to that table any more; I get a "table 'Category' not found" error message when I try to do db.SaveChanges().</p>
  
  <p>So I guess my question is this: when I created "MyTable" using the add-migration and update-database commands, did a class-to-table map get auto-generated somewhere behind the scenes? If so, can I access it and view it?</p>