title: Mapping to already existing database table
body: <p>I am using <code>Entity Framework 4.1 code first</code> to connect to an already existing database.  The table that I am using first is called <code>Bank</code>.  I also have a <code>Bank class</code> as my domain model.  This is how I mapped my class and table:</p>
  
  <pre><code>public class HbfContext : DbContext
  {
       public DbSet&lt;Bank&gt; Banks { get; set; }
  
       protected override void OnModelCreating(DbModelBuilder modelBuilder)
       {
            modelBuilder.Entity&lt;Bank&gt;().ToTable("Bank");
       }
  }
  </code></pre>
  
  <p>My Bank table:</p>
  
  <pre><code>BankID INT
  BankName VARCHAR(50)
  </code></pre>
  
  <p>My Bank class looks like this:</p>
  
  <pre><code>public class Bank
  {
       public int Id { get; set; }
       public string Name { get; set; }
       public bool IsActive { get; set; }
  }
  </code></pre>
  
  <p>I am having issues when I want to return all the banks.  The SQL statement returned from:</p>
  
  <pre><code>return db.Banks
       .OrderBy(x =&gt; x.Name);
  </code></pre>
  
  <p>is:</p>
  
  <pre><code>SELECT
       [Extent1].[Id] AS [Id],
       [Extent1].[Name] AS [Name],
       [Extent1].[IsActive] AS [IsActive]
  FROM
       [dbo].[Bank] AS [Extent1]
  ORDER BY
       [Extent1].[Name] ASC
  </code></pre>
  
  <p>This is not going to work because my table does not have the Id, Name and IsActive columns.  How would I fix this and would EF map BankId to Id and BankName to Name automatically?</p>