title: Proper way to delete record in LINQ to Entities
body: <p>I just have a very simple situation where all I need is to delete record using Linq2Entities. I tried to do some research and still can't figure out the right way to do it.</p>
  
  <p>Here's my simple code:</p>
  
  <pre><code>[DataObjectMethod(DataObjectMethodType.Delete)]
  public void DeleteEmployee(Employee z)
  {
      using (var ctx = new MyEntity())
      {
          var x = (from y in ctx.Employees
                   where  y.EmployeeId == z.EmployeeId
                   select y).FirstOrDefault();
           ctx.DeleteObject(x);
           ctx.SaveChanges();
      }
   }
  
  [DataObjectMethod(DataObjectMethodType.Select)]
  public List&lt;Employee&gt; GetAllEmployee()
  {
      using (var ctx = new MyEntity())
      {
          var x = from y in ctx.Employees
                  select y;
          return x.ToList();
      }
  }
  </code></pre>
  
  <p>I can delete a particular record if for example I assign <strong>y.EmployeeName == "Harold Javier"</strong> to the Delete method above, but when I assign <strong>y.EmployeeId == z.EmployeeId</strong> to the above code, the delete doesn't work. (Note: EmployeeId is the primary key of the Employee table)</p>