how to update Listdata with Linqpad and wcf?
-
10-12-2019 - |
Question
I am a lazy person, therefor I like to not scratch up a small concsole application if I don't need to.
I'd like to update a few listitems via Linqpad.
I can query the items just fine, but how do I update them? In my case I just need to replace the word "Neu" with "New" in a certain field.
//using OData calling /_vti_bin/listdata.svc
var ItemsToUpdate = Orders.Where(t => t.Status == "Neu")
foreach(var item in ItemsToUpdate)
{
item.Status.Dump();
item.Status = "New";
imte.Status.Dump();
}
Normally I'd call Context.SaveChanges() but in LinqPad I haven't defined a context. How can I submit my changes to the list? You see, that I use Dump() before and after the newly assigned Status value of New
. It goes like expected (neu New Neu New Neu New ....). The problem really just seems to be the submitting and saving of those changes.
Kind regards
Solution
the solution is as following:
foreach(var item in ItemstoUpdate)
{
item.Status = "New";
UpdateObject(item);
}
SaveChanges();
I didn't know I had to use UpdateObject(object)
OTHER TIPS
Can't you just type SaveChanges(); directly.