开发者

Update one Entity Based on Results of Another LINQ-to-Entities Query

I have the following LINQ-to-Entities query:

' 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

This will give me all the resident assignments for the current year/term. Then I have this LINQ-to-Entities query:

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

This will give me all the rooms. I want to iterate through the assignments and based on what room is assigned update the occupancy in reset_occupancy. I'm not 100% sure how to accomplish this. Here is my pseudo code of what I want to accomplish:

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


If someone has a better answer, I'd still like it...but for anyone else trying a similar process here is how I resolved it:

        ' 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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜