开发者

LINQ to Entities does not support the method...System.Object CompareObjectEqual

When I execute the code below I receive the error message:

LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.

It seems to be occurring on the line For Each row2 in PCstudent.

    Protected Sub btnPushSemester_Click(sender As Object, e As EventArgs) Handles btnPushSemester.Click
    Dim dbPC As New Campus6Entities
    Dim dbContext As New pbu_housingEntities
    Dim getOccupants
    Dim thisYear As String
    Dim thisTerm As String
    Using dbContext
        Dim get_Year = From p In dbContext.Configs _
                           Where p.Description = "year" _
                           Select p

        Dim get_Term = From p In dbContext.Configs _
                       Where p.Description = "term" _
                       Select p

        thisYear = get_开发者_C百科Year.First.textValue
        thisTerm = get_Term.First.textValue
        getOccupants = From p In dbContext.Residents _
                 Where p.semester = thisTerm _
                 Where p.year = thisYear _
                 Select p

        Using dbPC
            For Each row In getOccupants
                Dim student_info = row
                Dim people_id = student_info.people_code_id
                Dim building_code = student_info.Building1.building_code
                Dim room = student_info.Room1.room1
                Dim PCstudent = From r In dbPC.RESIDENCies _
                                Where r.PEOPLE_ID = people_id _
                                Where r.ACADEMIC_YEAR = thisYear _
                                Where r.ACADEMIC_TERM = thisTerm _
                                Select r

                For Each row2 In PCstudent
                    Dim student_info2 = row2
                    student_info2.DORM_BUILDING = building_code
                    student_info2.DORM_ROOM = room
                    student_info2.RESIDENT_COMMUTER = "R"
                    student_info2.DORM_CAMPUS = "O000000001"
                    dbPC.SaveChanges()
                Next
            Next
        End Using
    End Using

End Sub


First of all you're doing things the most difficult way possible (row by row update in code) instead of single update to the database; that said, nothing looks incorrect on the surface of things. You might check the definition of 'dbPC.Residencies' to make sure it's defined correctly, and you may need to put an "if (PCStudent.Any())" check before your "For Each", though it ought to work as written.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜