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() 
相关问题