SQL Linq, updating multiple records
-
I know how to update a single record, but updating multiple records is different. Single
Dim uTemplate As CRM_JOBS = context.crm_Jobs.Single(Function(m) m.templateName = templateName)
uTemplate.templateXHTML = sEMT.templateXHTML
uTemplate.templateID = pValue
context.SaveChanges()I thought of this for multiple records, but items doesn't carry over to the loop. So would I have to project it into something and then save?
Dim jobs =
From items In context.crm_Jobs
Where items.templateName = templateNameFor Each items In jobs
jobs.templateXHTML = sEMT.templateXHTML
jobs.templateID = pValue
Next
context.SaveChanges()[edit] I have this now
Dim jobs =
From j In context.crm_Jobs
Where j.templateName = templateName
Select jFor Each j As CRM_JOBS In jobs
j.templateXHTML = sEMT.templateXHTML
j.templateID = sEMT.templateID
Nextcontext.SaveChanges()
Oh that works!