linq to sql update data

Posted by pranay on Stack Overflow See other posts from Stack Overflow or by pranay
Published on 2010-05-20T09:14:54Z Indexed on 2010/05/20 9:30 UTC
Read the original article Hit count: 171

Filed under:

can i update my employee record as given in below function or i have to make query of employee collection first and than i update data

  public int updateEmployee(App3_EMPLOYEE employee)
    {
        DBContextDataContext db = new DBContextDataContext();
        db.App3_EMPLOYEEs.Attach(employee);
        db.SubmitChanges();
        return employee.PKEY;
    }

or i have to do this

 public int updateEmployee(App3_EMPLOYEE employee)
{
    DBContextDataContext db = new DBContextDataContext();
    App3_EMPLOYEE emp = db.App3_EMPLOYEEs.Single(e => e.PKEY == employee.PKEY);
    db.App3_EMPLOYEEs.Attach(employee,emp);
    db.SubmitChanges();
    return employee.PKEY;
}

But i dont want to use second option is there any efficient way to update data

© Stack Overflow or respective owner

Related posts about linq-to-sql