title: How to retrieve last insert id from database
body: <p>I inserted the data into a table using Entity Framework but now I need to retrieve the last id from last executed query.</p>
  
  <p>Here is my code </p>
  
  <pre><code>var filedbdata = "'" + FileTitle + "'" + "," +
                   "'" + path + "'" + "," +
                   "'" + Session["UserID"] + "'";
  
  var query = "insert into File_Upload(file_title,file_loc,file_userid) values(" + filedbdata + ")";
  
  db.Database.ExecuteSqlCommand(query);
  db.SaveChanges();
  
  int lastid = ??
  </code></pre>