I am wondering what the best way to update multiple records with Entity Framework is. This is how I normally do it, and it does work:
private static void SetNcprpCodesAsComplete(string[] ncprpCodes)
{
using (var ent = new Data.Entities())
{
var query = from ba in ent.BuildingAssessments
where ncprpCodes.Contains(ba.NcprpCode)
select ba.TabletAssessment;
foreach (var ta in query) ta.Complete = true;
ent.SaveChanges();
}
}
This query should also work (is one better than the other)
var query = from ta in ent.TabletAssessments
where ncprpCodes.Contains(ta.BuildingAssessment.NcprpCode)
select ta;
Another way could be looping through the string[]
, attaching and updating. Is it possible to attach when doing a multi table query like this?