title: Change column name on model creating with Entity Framework
body: <p>I'm looking for any solution to change the column names during building the database using Entity Framework.</p>
  
  <p>I have a sample code below:</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      base.OnModelCreating(modelBuilder);
      modelBuilder.Entity&lt;SysUser&gt;().Property(p =&gt; p.Enable).HasColumnName("newColumnName");
  }
  </code></pre>
  
  <p>This works, but I want to automate this action of changing the column names, i.e. get some part of entities, and change the column name.</p>
  
  <p>To do this, I wrote the code below, but I'm stuck. To get all entities, I used <code>Types</code>, which can't be converted into <code>EntityTypeConfiguration&lt;&gt;</code>.</p>
  
  <pre><code>// This gets all of defined DbSet&lt;&gt; in database contexts
  var contextProp = this.GetType().GetProperties().Where(p =&gt; (p.PropertyType.GetGenericArguments().Count() == 1)).ToList();
  
  foreach (PropertyInfo entity in contextProp )
  {
     // get generic type from DbSet
     Type entityType = entity.PropertyType.GetGenericArguments()[0];
     foreach (PropertyInfo entityProp in entityType.GetProperties())
     {
        // I'm stuck here
        // entityType = SysUser
        // entityProp = Enable
     }
  }
  </code></pre>
  
  <p>Why am I doing this? Beceuse in one class I have another class.
  Entity Framework renders fields adding the method name at the end of column name.</p>
  
  <p>For example:</p>
  
  <pre><code>public class x
  {
     public int Value { get; set; }
  }
  
  public class y
  {
     public x { get; set; }
  }
  
  // ... some database context
  DbSet&lt;y&gt; y { get; set; }
  </code></pre>
  
  <p>The database is created with a table named <code>y</code> with a column named <code>x_Value</code>.</p>
  
  <p>I can't use <code>ColumnAttribute</code>, because this option sets the same column name for all classes. Name of columns should be the same as property <code>x { get; set; }</code>.</p>