sql server - linq to sql , can not solve big sql statement into linq -


i trying hard cannot reach result. new linq. should proper linq query sql query. please me out of this.

update teacher set remainingcredit = remainingcredit- course.credit  courseassignteacher  join course on courseassignteacher.courseid = course.id join teacher on courseassignteacher.teacherid = teacher.id courseassignteacher.id = 1 

write query selects want update, use foreach loop , context.submitchanges:

using (dbdatacontext db = new dbdatacontext()) {     var toupdate = cat in db.courseassignteacher                    join c in db.course on cat.courseid equals c.id                    join t in db.teacher on cat.teacherid equals t.id                    cat.id = 1                    select new { teacher = t, course = c, courseassignteacher = cat };     foreach (var x in toupdate)     {         x.teacher.remainingcredit = x.teacher.remainingcredit - x.course.credit;     }      db.submitchanges(); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -