当我执行下面的代码时,收到错误消息:
LINQ to Entities无法识别方法'System.Object CompareObjectEqual(System.Object,System.Object,Boolean)'方法,并且此方法无法转换为商店表达式。
似乎发生在PCstudent的每行2的行上。
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_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
答案 0 :(得分:1)
首先,您正在以最困难的方式(在代码中逐行更新)而不是对数据库进行单一更新;也就是说,事情表面上任何看起来都不正确。您可以检查'dbPC.Residencies'的定义以确保它被正确定义,并且您可能需要在“For Each”之前设置“if(PCStudent.Any())”,但它应该按照书面形式工作