title: Get identity value after insert in entity framework while using dependancy injection
body: <p>I am using entity frame work in my mvc core application. I am also using dependency injection technique. Now i want to get the value of new record identity column. I am using the code as..</p>
  
  <pre><code>public interface IGenericRepositoryStudent&lt;T&gt; where T : class
  {
      void Add(T item);
  }
  
  public class GenericRepositoryStudent&lt;T&gt; : IGenericRepositoryStudent&lt;T&gt; where T : class
  {
      private eerp_studentContext _context;
      private DbSet&lt;T&gt; _dbSet;
  
      public GenericRepositoryStudent(eerp_studentContext context)
      {
          _context = context;
          _dbSet = _context.Set&lt;T&gt;();
      }
  
      public void Add(T item)
      {
          _dbSet.Add(item);
          _context.SaveChanges();
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class StudentController : Controller
  {
      private IStudentRepository _dbSet;
  
      public StudentController(IStudentRepository dbSet)
      {
          _dbSet = dbSet;
      }
  
      public long Add([FromBody]Student _student)
      {
          if (ModelState.IsValid)
          {
              _dbSet.Add(acJournal);
              long _id = _student.id; // value of _id is always 0.
              return _id;
          }
      }
  }
  </code></pre>