title: Column name defaults overridden, but generated queries still refer to undefined column
body: <p>I have a LINQ query (that involves a join) that fails with an exception that I know is coming out of the naming conventions and assumptions that Entity Framework makes, but I cannot find out where that setting is or how to shut it off.  The exception I get is:</p>
  
  <pre><code>ORA-00904: \"Extent2\".\"Client_PermanentClientId\": invalid identifier"
  </code></pre>
  
  <p>There is no such column in any of our tables, it is a combination of a table name (<code>Client</code>) and a column (<code>PermanentClientId</code>), but I have overridden (or so I thought) all of the column name defaults with <code>.HasColumnName()</code>.</p>
  
  <p>Can anyone tell me where I go in EF to turn off the creation of this name, or why it's spinning this up?</p>
  
  <p>Client Class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  using Paychex.IP.Common.Validation;
  
  
  namespace Paychex.IP.Common.IPEntities.Models
  {
      [Serializable]
      [Table("CLIENT")]
      public class Client : IPEntity
      {
          #region Entity properties and validation attributes
  
          [Key]
          [Range(1, int.MaxValue, ErrorMessage = "Client: PermanentClientId cannot be zero")]
          public int PermanentClientId { get; set; }
  
          public int AssociateNumber { get; set; }
  
          public int ClientNumber { get; set; }
  
          [StringLength(50, ErrorMessage = "Client: ClientName is limited to 50 characters")]
          public string ClientName { get; set; }
  
          [StringLength(30, ErrorMessage = "Client: Address1 is limited to 30 characters")]
          public string Address1 { get; set; }
  
          [StringLength(30, ErrorMessage = "Client: Address2 is limited to 30 characters")]
          public string Address2 { get; set; }
  
          [StringLength(24, ErrorMessage = "Client: City is limited to 24 characters")]
          public string City { get; set; }
  
          [StringLength(2, ErrorMessage = "Client: State is limited to 2 characters")]
          public string State { get; set; }
  
          [StringLength(10, ErrorMessage = "Client: ZipCode is limited to 10 characters")]
          public string ZipCode { get; set; }
  
          [StringLength(3, ErrorMessage = "Client: Country is limited to 3 characters")]
          public string Country { get; set; }
  
          [StringLength(3, ErrorMessage = "Client: ClientType is limited to 3 characters")]
          public string ClientType { get; set; }
  
          [StringLength(30, ErrorMessage = "Client: DoingBusinessAs is limited to 30 characters")]
          public string DoingBusinessAs { get; set; }
  
          [StringLength(30, ErrorMessage = "Client: Contact is limited to 30 characters")]
          public string Contact { get; set; }
  
          [StringLength(30, ErrorMessage = "Client: PhoneNumber is limited to 20 characters")]
          public string PhoneNumber { get; set; }
  
          [StringLength(10, ErrorMessage = "Client: Extension is limited to 10 characters")]
          public string Extension { get; set; }
  
          [StringLength(20, ErrorMessage = "Client: FaxNumber is limited to 20 characters")]
          public string FaxNumber { get; set; }
  
          [StringLength(10, ErrorMessage = "Client: FaxExtension is limited to 10 characters")]
          public string FaxExtension { get; set; }
  
          [StringLength(50, ErrorMessage = "Client: Email is limited to 50 characters")]
          public string Email { get; set; }
  
          public int NextEmployeeNumber { get; set; }
  
          [StringLength(15, ErrorMessage = "Client: PayFrequency is limited to 15 characters")]
          public string PayFrequency { get; set; }
  
          [StringLength(10, ErrorMessage = "Client: EmployeeSort is limited to 10 characters")]
          public string EmployeeSort { get; set; }
  
          [DbBoolValidation("Client: UseDivisions is not a valid DbBool")]
          public string UseDivisions { get; set; }
  
          [StringLength(10, ErrorMessage = "Client: ClientAccessType is limited to 10 characters")]
          public string ClientAccessType { get; set; }
  
          public string AutopayWageId { get; set; }
  
          public string Fein { get; set; }
  
          [DbBoolValidation("Client: HrModule is not a valid DbBool")]
          public string HrModule { get; set; }
  
          public int BankCode { get; set; }
  
          public int AchDays { get; set; }
  
          public string AchCollect { get; set; }
  
          [DbBoolValidation("Client: Updated is not a valid DbBool")]
          public string Updated { get; set; }
  
          [DbBoolValidation("Client: IatFlag is not a valid DbBool")]
          public string IatFlag { get; set; }
  
          [StringLength(50, ErrorMessage = "Client: OriginalEmail is limited to 50 characters")]
          public string OriginalEmail { get; set; }
  
          public virtual ICollection&lt;ClientWage&gt; Wages { get; set; }
          public virtual ICollection&lt;ClientDivision&gt; Divisions { get; set; }
          public virtual ICollection&lt;ClientDepartment&gt; Departments { get; set; }
          public virtual ICollection&lt;ClientJob&gt; Jobs { get; set; }
          public virtual ICollection&lt;ClientDeduction&gt; Deductions { get; set; }
  
          #endregion
  
          #region IValidatableObject interface implementation
  
          // No custom validation for now
  
          #endregion
  
          #region IValidationHelper interface implementation
  
          public override void PopulateContext(ValidationContext context)
          {
              context.Items.Clear();
              context.Items.Add("PermanentClientId", PermanentClientId);
              context.Items.Add("ClientName", ClientName);
              context.Items.Add("Address1", Address1);
              context.Items.Add("Address2", Address2);
              context.Items.Add("City", City);
              context.Items.Add("State", State);
              context.Items.Add("ZipCode", ZipCode);
              context.Items.Add("Country", Country);
              context.Items.Add("ClientType", ClientType);
              context.Items.Add("DoingBusinessAs", DoingBusinessAs);
              context.Items.Add("Contact", Contact);
              context.Items.Add("PhoneNumber", PhoneNumber);
              context.Items.Add("Extension", Extension);
              context.Items.Add("FaxNumber", FaxNumber);
              context.Items.Add("FaxExtension", FaxExtension);
              context.Items.Add("Email", Email);
              context.Items.Add("PayFrequency", PayFrequency);
              context.Items.Add("EmployeeSort", EmployeeSort);
              context.Items.Add("UseDivisions", UseDivisions);
              context.Items.Add("ClientAccessType", ClientAccessType);
              context.Items.Add("HrModule", HrModule);
              context.Items.Add("Updated", Updated);
              context.Items.Add("IatFlag", IatFlag);
              context.Items.Add("OriginalEmail", OriginalEmail);
          }
  
          #endregion
      }
  }
  </code></pre>
  
  <p>The Client_map class:</p>
  
  <pre><code>using System.Data.Entity.ModelConfiguration;
  
  namespace Paychex.IP.Common.IPEntities.Models.Mappings
  {
      public class Client_map : EntityTypeConfiguration&lt;Client&gt;
      {
          public Client_map()
          {
              this.ToTable("CLIENT", "INSTANTPAY");
  
              // Primary Key
              this.HasKey(t =&gt; t.PermanentClientId);
  
              // Column Properties
  
              this.Property(t =&gt; t.PermanentClientId)
                  .HasColumnName("PCLIENT_ID");
  
              this.Property(t =&gt; t.AssociateNumber)
                  .HasColumnName("ASSOCIATE_NO");
  
              this.Property(t =&gt; t.ClientNumber)
                  .HasColumnName("CLIENT_NO");
  
              this.Property(t =&gt; t.ClientName)
                  .HasColumnName("CLIENT_NAME");
  
              this.Property(t =&gt; t.Address1)
                  .HasColumnName("ADDRESS1");
  
              this.Property(t =&gt; t.Address2)
                  .HasColumnName("ADDRESS2");
  
              this.Property(t =&gt; t.City)
                  .HasColumnName("CITY");
  
              this.Property(t =&gt; t.State)
                  .HasColumnName("STATE");
  
              this.Property(t =&gt; t.ZipCode)
                  .HasColumnName("ZIP");
  
              this.Property(t =&gt; t.Country)
                  .HasColumnName("COUNTRY");
  
              this.Property(t =&gt; t.ClientType)
                  .HasColumnName("CLIENT_TYPE");
  
              this.Property(t =&gt; t.DoingBusinessAs)
                  .HasColumnName("DOING_BUSINESS_AS");
  
              this.Property(t =&gt; t.Contact)
                  .HasColumnName("CONTACT");
  
              this.Property(t =&gt; t.PhoneNumber)
                  .HasColumnName("PHONE");
  
              this.Property(t =&gt; t.Extension)
                  .HasColumnName("EXTENSION");
  
              this.Property(t =&gt; t.FaxNumber)
                  .HasColumnName("FAX");
  
              this.Property(t =&gt; t.FaxExtension)
                  .HasColumnName("FAX_EXTENSION");
  
              this.Property(t =&gt; t.Email)
                  .HasColumnName("EMAIL");
  
              this.Property(t =&gt; t.NextEmployeeNumber)
                  .HasColumnName("NEXTEMP");
  
              this.Property(t =&gt; t.PayFrequency)
                  .HasColumnName("PAY_FREQ");
  
              this.Property(t =&gt; t.EmployeeSort)
                  .HasColumnName("EMPSORT");
  
              this.Property(t =&gt; t.UseDivisions)
                  .HasColumnName("DIVUSE");
  
              this.Property(t =&gt; t.ClientAccessType)
                  .HasColumnName("CLIENT_ACCESS_TYPE");
  
              this.Property(t =&gt; t.AutopayWageId)
                  .HasColumnName("AUTOPAY_WAGE_ID");
  
              this.Property(t =&gt; t.Fein)
                  .HasColumnName("FEIN");
  
              this.Property(t =&gt; t.HrModule)
                  .HasColumnName("HR_MODULE");
  
              this.Property(t =&gt; t.BankCode)
                  .HasColumnName("BANK_CODE");
  
              this.Property(t =&gt; t.AchDays)
                  .HasColumnName("ACH_DAYS");
  
              this.Property(t =&gt; t.AchCollect)
                  .HasColumnName("ACH_COLLECT");
  
              this.Property(t =&gt; t.Updated)
                  .HasColumnName("UPDATED");
  
              this.Property(t =&gt; t.IatFlag)
                  .HasColumnName("IAT_FLAG");
  
              this.Property(t =&gt; t.OriginalEmail)
                  .HasColumnName("ORIG_EMAIL");
          }
      }
  }
  </code></pre>
  
  <p>In the DbContext-derived classes, we override the OnModelCreating method and use the map classes to define each table.  Here is one of the related classes map file:</p>
  
  <pre><code>using System.Data.Entity.ModelConfiguration;
  
  
  namespace Paychex.IP.Common.IPEntities.Models.Mappings
  {
      public class ClientDeduction_map : EntityTypeConfiguration&lt;ClientDeduction&gt;
      {
          public ClientDeduction_map()
          {
              // Primary Key
              this.HasKey(t =&gt; new { t.PermanentClientId, t.DeductionId });
  
              this.ToTable("CLIENTDEDUCTION", "INSTANTPAY");
  
              // Column Properties
  
              this.Property(t =&gt; t.PermanentClientId)
                  .HasColumnName("PCLIENT_ID")
                  .IsRequired();
  
              this.Property(t =&gt; t.DeductionId)
                  .HasColumnName("DEDUCTION_ID")
                  .IsRequired();
  
              this.Property(t =&gt; t.Active)
                  .HasColumnName("ACTIVE")
                  .HasMaxLength(1);
  
              this.Property(t =&gt; t.AllowOnLevy)
                  .HasColumnName("ALLOW_ON_LEVY")
                  .HasMaxLength(1);
  
              this.Property(t =&gt; t.AnnualLimit)
                  .HasColumnName("ANNUAL_LIMIT")
                  .HasPrecision(9, 2);
  
              this.Property(t =&gt; t.Frequency)
                  .HasColumnName("FREQUENCY");
  
              this.Property(t =&gt; t.LimitPerPay)
                  .HasColumnName("LIMIT_PER_PAY")
                  .HasPrecision(5, 2);
  
              this.Property(t =&gt; t.Description)
                  .HasColumnName("DESCRIPTION")
                  .HasMaxLength(20);
  
              this.Property(t =&gt; t.PaceId)
                  .HasColumnName("PACE_ID");
  
              this.Property(t =&gt; t.Priority)
                  .HasColumnName("PRIORITY");
  
              this.Property(t =&gt; t.RateType)
                  .HasColumnName("RATE_TYPE")
                  .HasMaxLength(10);
  
              this.Property(t =&gt; t.ShortDescription)
                  .HasColumnName("SHORTDESC")
                  .HasMaxLength(5);
  
              this.Property(t =&gt; t.VendorId)
                  .HasColumnName("VENDOR_ID")
                  .HasMaxLength(8);
  
              this.HasRequired(t =&gt; t.Client)
                  .WithMany(w =&gt; w.Deductions)
                  .HasForeignKey(t =&gt; new { t.PermanentClientId });
  
          }
      }
  }    
  </code></pre>
  
  <p>And finally, the OnModelCreating override:</p>
  
  <pre><code>       protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Conventions.Remove&lt;ColumnTypeCasingConvention&gt;();
  
          var mbClient = new Client_map();
          modelBuilder.Configurations.Add(mbClient);
  
          var mbActivePayrolls = new ActivePayroll_map();
          modelBuilder.Configurations.Add(mbActivePayrolls);
  
          var mbPaychecks = new Paycheck_map();
          modelBuilder.Configurations.Add(mbPaychecks);
  
          var mbPaychecktax = new PaycheckTax_map();
          modelBuilder.Configurations.Add(mbPaychecktax);
  
          var mbPaycheckwage = new PaycheckWage_map();
          modelBuilder.Configurations.Add(mbPaycheckwage);
  
          var mbPaycheckDeduction = new PaycheckDeduction_map();
          modelBuilder.Configurations.Add(mbPaycheckDeduction);
  
          var mbStates= new State_map();
          modelBuilder.Configurations.Add(mbStates);
  
          var mbClientHeaderSchedule = new ClientScheduleHeader_map();
          modelBuilder.Configurations.Add(mbClientHeaderSchedule);
  
          var mbClientDepartment = new ClientDepartment_map();
          modelBuilder.Configurations.Add(mbClientDepartment);
  
          var mbClientDivision = new ClientDivision_map();
          modelBuilder.Configurations.Add(mbClientDivision);
  
          var mbClientWage = new ClientWage_map();
          modelBuilder.Configurations.Add(mbClientWage);
  
          var mbViewEmployeeList = new ViewEmployeeList_map();
          modelBuilder.Configurations.Add(mbViewEmployeeList);
  
  
          base.OnModelCreating(modelBuilder);
      }
  </code></pre>