title: Need to map an EF entity property to a column using another property's name
body: <p>I <em>took out logic from the accessors</em> to make the code cleaner.  I have a table with a column named "Answer" and I have existing code that uses the entity property "Answer".  I need to minimize changes to the db and code base.  </p>
  
  <p>The requirement is that Answer is to be encrypted only sometimes.  What I would like to do is reuse the Answer property, but map a different property to the database using the same column name.</p>
  
  <p>This way, the Answer property always returns a decrypted value but the encrypted value is persisted in the db.  I only need the value encrypted at rest and only certain "answers" are encrypted, not all.</p>
  
  <p>It would be perfect if I could do the following code; however, I get this exception:</p>
  
  <pre><code>{"The property 'Answer' is not a declared property on type 'NewHireAnswer'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property."}
  </code></pre>
  
  <p>I've tried manually configuring the column mappings in the OnModelCreating method of the DbContext, as well, with the same exception.</p>
  
  <pre><code>[NotMapped]
  public string Answer 
  {
      get { return _internalAnswer; }
      set { InternalAnswer = value; }
  }
  
  private string _internalAnswer;
  [Column("Answer")]
  public string InternalAnswer 
  {
      get { return _internalAnswer; }
      set { _internalAnswer = value; }
  }
  </code></pre>
  
  <p>Perhaps, the only way to do this is to rename the column, but, as I said I need to reduce that type of configuration change.  And it seems as though I should be able to do what I'm trying.</p>
  
  <p><strong>Update:</strong>  I noticed that in the VB.Net examples, that the property setter is never used in conjunction with &lt;<em>NotMapped</em>> on String properties.  So maybe the issue isn't that I'm trying to map to another property's name, but instead, that I can't use a String property with &lt;<em>NotMapped</em>> and a setter.  The exception message does say "<em>Make sure that it is a valid primitive property</em>".</p>
  
  <p>That seems to be a very weird combination of constraints.  I should be able to have non-mapped property that I can use to set/get, or whatever, shouldn't I?</p>
  
  <p><strong><em>Update:</em></strong> I created two new code first projects, one c# and one Vb.Net, and  what I'm trying to do above works fine.  This leads me to believe it's a configuration issue.</p>
  
  <p>This is what is in the OnModelCreating method of my DbContext:</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      base.OnModelCreating(modelBuilder);
  
      EFHelpers.StringHelper.DisableUnicodeForAllEntityStrings(this, modelBuilder);
  
      TurnOnCascadeDeletes(modelBuilder);
      TurnOffCascadeDeletes(modelBuilder);
      MapTables(modelBuilder);
  
  }
  </code></pre>