title: Get Id of Generic Entity of EF 6
body: <p>I write a generic repository to CRUD in EF.In add method is written like this</p>
  
  <pre><code>public class GenericRepo&lt;T&gt; where T : class
  {
          //Create
          public static void Add(CellPhoneProjectEntities dbContext, T entity)
          {
              dbContext.Set&lt;T&gt;().Add(entity);
              dbContext.SaveChanges();
          }
  }
  </code></pre>
  
  <p>works fine by i want to get first element of the Entity(Primary key ,Identity column )</p>
  
  <pre><code>public static long Add(CellPhoneProjectEntities dbContext, T entity,long id)
          {
              dbContext.Set&lt;T&gt;().Add(entity);
              dbContext.SaveChanges();
  
              var pk = entity.ElementType.KeyMembers[0];
              //Something like first elemnt by generic
              return pk as Long;
          }
  </code></pre>
  
  <p>can anyone help to get First element(Id) of entity after insertion?</p>
  
  <p>EDIT: EF database first and my primary key is not named Id..</p>
  
  <p>Rather it is TableNameId eg. Table <strong>ProjectMaster</strong> has primary key <strong>ProjectMasterId</strong></p>