简体   繁体   中英

Update Operation in LINQ to SQL

I want to update one column in LINQ to SQL. My Query is like :-

private void UpdateCourse()
{
      OperationDataContext OdContext = new OperationDataContext();
      //Get Single course which need to update
      COURSE objCourse = OdContext.COURSEs.Single(course => course.course_name == "B.Tech");
      //Field which will be update
      objCourse.course_desc = "Bachelor of Technology";
      // executes the appropriate commands to implement the changes to the database
      OdContext.SubmitChanges();
}

My question is first it take record from COURSEs which match the criteria Than it update it. It this right approach? or SP is right solution here.

Suggest!

It doesn't really matter. Either way will work. if you are asking which is more efficient, stored procedures are generally more efficient, but the update above works just fine, and keeps all of the update logic within the application code.

As far as what gets updated, run SQL profiler, and you'll see how LINQ crafts the update statement against the database, and weigh the options yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM