0

我有以下的LINQ到實體查詢:基於另一個LINQ到實體的結果更新一個實體查詢

' Get all the residency assignments that match the term/year. 
     Dim assignments = From p In dbContext.Residents _ 
          Where p.semester = term _ 
          Where p.year = year _ 
          Select p 

這會給我所有本年度/學期駐地分配。然後我有這個LINQ-to-Entities查詢:

Dim reset_occupancy = From p In dbContext.Rooms _ 
           Select p 

這會給我所有的房間。我想遍歷任務,並根據分配的房間更新reset_occupancy中的佔用情況。我不是100%確定如何做到這一點。這裏是什麼,我要完成我的僞代碼:

For each row in assignments 
    reset_occupancy.Where(reset_occupancy.room=assignment.occupancy).current_occupancy =+1 
Next 

回答

0

如果有人有更好的答案,我還是喜歡它,而是爲了其他人在這裏嘗試了類似的過程是怎麼解決它:

 ' Now, retabulate current occupancy. 
     For Each row In assignments 
      Dim assignment As Integer = row.room 
      Dim update_occupancy = (From p In dbContext.Rooms _ 
            Where p.id = assignment _ 
            Select p).FirstOrDefault 

      update_occupancy.current_occupancy = update_occupancy.current_occupancy + 1 
     Next 
     dbContext.SaveChanges() 
相關問題