简体   繁体   中英

Update values in IQueryable object

I have an IQueryable object and I want to update some values manually, but the changes are not reflected after the loop is executed:

 IQueryable<myModel> items;
 items = GetItems();   

 foreach (myModel row in items)
 {
        row.field10 = "new value";
 }

 objDataContext.SubmitChanges();

What am I doing wrong?

Does GetItems() method use exactly the same instance of objDataContext to get the items from the database? It has to use the same ObjectContext to keep track of changes. Another option is to use the ToList() method:

List<myModel> items = GetItems().ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM