title: How To Get Last Inserted Row From Table Using LINQ?
body: <p>Employee</p>
  
  <p>Empid | EmployeeName<br>
  1-------------Ron<br>
  2------------John  <br></p>
  
  <p>Department</p>
  
  <p>Depid | DepartmentName | Status| Empid<br>
  1---------------Account--------- 1---------1<br>
  2---------------HR----------------1---------1<br> 
  3---------------Finance----------1---------2<br> 
  4---------------Design-----------1---------2<br> </p>
  
  <p>Here I have two table Employee and Department. One employee can be in different department such as empid = 1 in two department i.e account and hr similarly empid = 2 in two department i.e finance and design .<br> Now, for example since empid = 1 is inserted in depid = 1 and depid = 2 but I am tryingto get depid = 2 which is last inserted row for empid = 2.Similarly, for empid = 2 last row of department which is depid = 4.<br>
  Now, the problem is that my LINQ join doesnot give the required output.<br>
  Since i am very much new to Linq, help will be highly appreciated.Thank you<br><br>
  Below is my LINQ Join<br></p>
  
  <pre><code> var empDepList = (from D in db.Department.Where(x =&gt; x.Status == 1)
                     join E in db.Employee on D.Empid equals E.Empid
                     select new
                     {
                       D.DepartmentName, E.EmployeeName
                     }).ToList();
  </code></pre>