title: Table Name Mapping not working in EF 6 when using POCO classes
body: <p>I am using System.ComponentModel.DataAnnotations.Schema.TableAttribute in class below, so class 'Order_Details' is mapped to table 'Order Details' in Northwind database.  </p>
  
  <p>There is an attribute [Table("Order Details"] just above class definition to map it to a database table.</p>
  
  <p>The problem is when a LINQ query executes against the database, it tries to query 'Order_Details' table in the database, when it should be querying 'Order Details' table.</p>
  
  <p><strong>Question</strong>: Do I have to use some other attribute for mapping this class to 'Order Details' table in the database? This POCO class ( without the table attribute) was generated by a third-party code generator using Entity Framework.</p>
  
  <pre><code>[Table("Order Details")]
  public class Order_Details
  {
      [Key]
      [Column(Order = 0)]
      [Required]
      [Display(Name = "Order I D")]
      public Int32 OrderID { get; set; }
  
      [Key]
      [Column(Order = 1)]
      [Required]
      [Display(Name = "Product I D")]
      public Int32 ProductID { get; set; }
  
      [Required]
      [Display(Name = "Unit Price")]
      public Decimal UnitPrice { get; set; }
  
      [Required]
      [Display(Name = "Quantity")]
      public Int16 Quantity { get; set; }
  
      [Required]
      [Display(Name = "Discount")]
      public Decimal Discount { get; set; }
  
      // ComboBox
      public virtual Orders Orders { get; set; }
      public virtual Products Products { get; set; }
  
  }
  </code></pre>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>Since there was no edmx file and it was using  'Code first fluent API' as suggested by Jeow Li Huan in his answer, I add a table mapping for 'Order Details' in modelcreating event and it worked then.</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              base.OnModelCreating(modelBuilder);
  
              //added this in place of Table attribute and it works
              modelBuilder.Entity&lt;Order_Details&gt;().ToTable("Order Details");
  
              modelBuilder.Entity&lt;Orders&gt;().ToTable("Orders");
              modelBuilder.Entity&lt;Products&gt;().ToTable("Products");
              modelBuilder.Entity&lt;Customers&gt;().ToTable("Customers");
              modelBuilder.Entity&lt;Employees&gt;().ToTable("Employees");
              modelBuilder.Entity&lt;Shippers&gt;().ToTable("Shippers");
              modelBuilder.Entity&lt;Suppliers&gt;().ToTable("Suppliers");
              modelBuilder.Entity&lt;Categories&gt;().ToTable("Categories");
  
          }
  </code></pre>
  
  <p><strong>UPDATE 2</strong>:</p>
  
  <p>Also, another solution as suggested by Jeow, was to remove the model creating event and just use the original table attribute. This also worked.</p>