Most efficient way to update with LINQ to SQL

前端 未结 6 1296
臣服心动
臣服心动 2020-12-28 16:50

Can I update my employee record as given in the function below or do I have to make a query of the employee collection first and then update the data?

  pub         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 17:41

    You can attach a unattached modified entity, by using this overload:

    db.App3_EMPLOYEEs.Attach(employee, true);//Attach as modfieied
    

    Note that for this to work you need in your table a "Version" column of type "timestamp"

提交回复
热议问题