title: Improve navigation property names when reverse engineering a database
body: <p>I'm using Entity Framework 5 with Visual Studio with Entity Framework Power Tools Beta 2 to reverse engineer moderately sized databases (~100 tables).</p>
  
  <p>Unfortunately, the <strong>navigation properties do not have meaningful names</strong>. For example, if there are two tables:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE Contacts (
      ContactID INT IDENTITY (1, 1) NOT NULL,
      ...
      CONSTRAINT PK_Contacts PRIMARY KEY CLUSTERED (ContactID ASC)
  }
  
  CREATE TABLE Projects (
      ProjectID INT IDENTITY (1, 1) NOT NULL,
      TechnicalContactID INT NOT NULL,
      SalesContactID INT NOT NULL,
      ...
      CONSTRAINT PK_Projects PRIMARY KEY CLUSTERED (ProjectID ASC),
      CONSTRAINT FK_Projects_TechnicalContact FOREIGN KEY (TechnicalContactID)
          REFERENCES Contacts (ContactID),
      CONSTRAINT FK_Projects_SalesContact FOREIGN KEY (SalesContactID)
          REFERENCES Contacts (ContactID),
      ...
  }
  </code></pre>
  
  <p>This will generate classes like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Contact
  {
       public Contact()
       {
            this.Projects = new List&lt;Project&gt;();
            this.Projects1 = new List&lt;Project&gt;();
       }
       public int ContactID { get; set; }
       // ...
       public virtual ICollection&lt;Project&gt; Projects { get; set; }
       public virtual ICollection&lt;Project&gt; Projects1 { get; set; }
  }
  
  public class Project
  {
       public Project()
       {
  
       }
       public int ProjectID { get; set; }
       public int TechnicalContactID { get; set; }
       public int SalesContactID { get; set; }
       // ...
       public virtual Contact Contact { get; set; }
       public virtual Contact Contact1 { get; set; }
  }
  </code></pre>
  
  <p>I see several variants which would all be better than this:</p>
  
  <ul>
  <li>Use the <strong>name of the foreign key</strong>: For example, everything after the last underscore (<code>FK_Projects_TechnicalContact</code> --> <code>TechnicalContact</code>). Though this probably would be the solution with the most control, this may be more difficult to integrate with the existing templates.</li>
  <li>Use the <strong>property name</strong> corresponding to the foreign key column: Strip off the suffix <code>ID</code> (<code>TechnicalContactID</code> --> <code>TechnicalContact</code>)</li>
  <li>Use the <strong>concatenation of property name and the existing solution</strong>: Example <code>TechnicalContactIDProjects</code> (collection) and <code>TechnicalContactIDContact</code></li>
  </ul>
  
  <p>Luckily, <a href="http://romiller.com/2012/05/09/customizing-reverse-engineer-code-first-in-the-ef-power-tools/">it is possible to modify the templates by including them in the project</a>. </p>
  
  <p>The modifications would have to be made to <code>Entity.tt</code> and <code>Mapping.tt</code>. I find it difficult due to the lack of intellisense and debug possibilities to make those changes.</p>
  
  <hr>
  
  <p><em>Concatenating property names</em> (third in above list) is probably the easiest solution to implement.</p>
  
  <p><strong>How to change the creation of navigational properties in <code>Entity.tt</code> and <code>Mapping.tt</code> to achieve the following result</strong>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Contact
  {
       public Contact()
       {
            this.TechnicalContactIDProjects = new List&lt;Project&gt;();
            this.SalesContactIDProjects = new List&lt;Project&gt;();
       }
       public int ContactID { get; set; }
       // ...
       public virtual ICollection&lt;Project&gt; TechnicalContactIDProjects { get; set; }
       public virtual ICollection&lt;Project&gt; SalesContactIDProjects { get; set; }
  }
  
  public class Project
  {
       public Project()
       {
  
       }
       public int ProjectID { get; set; }
       public int TechnicalContactID { get; set; }
       public int SalesContactID { get; set; }
       // ...
       public virtual Contact TechnicalContactIDContact { get; set; }
       public virtual Contact SalesContactIDContact { get; set; }
  }
  </code></pre>