根据另一个 LINQ 到实体查询的结果更新一个实体

发布于 2024-10-31 02:14:06 字数 714 浏览 0 评论 0原文

我有以下 LINQ-to-Entities 查询:

' 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

这将为我提供所有房间。我想迭代分配并根据分配的房间更新重置占用率中的占用率。我不是 100% 确定如何实现这一点。这是我想要完成的伪代码:

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

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很快妥协 2024-11-07 02:14:06

如果有人有更好的答案,我仍然喜欢它......但对于其他尝试类似过程的人来说,我是如何解决它的:

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文