我有一些 linq to sql 代码。如果我将其作为 for 循环运行,它会更新底层数据库,如下所示:
Dim myDC As MyDataClassDataContext = New MyDataClassDataContext
Dim processThese As List(Of rec) = (From k In myDC.recs Where k.didSomeStuff = false select k).toList
For Each o As rec In processThese
'do some stuff
o.didSomeStuff= True
myDC.SubmitChanges()
Next
但如果我这样运行它就不会
Dim myDC As MyDataClassDataContext = New MyDataClassDataContext
While (From k In myDC.recs Where k.didSomeStuff = False Select k).Count > 0
Dim o as Rec = (From l in myDC.recs where l.didSomeStuff=false select l).first
'do some stuff
o.didSomeStuff=true
mydc.submitchanges()
end while
这可能是什么原因?有什么关于while循环会抛出linq的东西吗?