I have what I think is a simple situation - but I've been stuck on it for a while now.
I am simply querying the database, and putting the results into a viewmodel: CallVM - that part works fine.
What I then want to do, it loop through the QueueByTeam object, and update one of the properties - however, the "looping" part, doesn't save the changes to the QueueByTeam object, so when I return the object to the View, my updates have been ignored:
var QueueByTeam = db.Calls.Where(x => x.assignedteam == id)
.Select(call => new CallVM
{
customer = call.customer,
nexttargetdate = call.nexttargetdate
owner = "";
});
foreach (var calls in QueueByTeam)
{
calls.owner = "--------";
}
// at this point, QueueByTeam has ignored changing the `owner` field to "-------"
return View(QueueByTeam.ToList());
Do I need to do something after the foreach loop to save the changes, before returning to the View?
Thanks, Mark
ToList()statement on the end of the select statement. This would force the read of the database and store it locally?calls.owner = "-----" in place ofowner = ""`?call => new CallVM. Your query creates new unattached objects and the query is executed 2x.