在運行以下附上我的代碼收到錯誤索引屬性錯誤:必須是合格和參數顯式提供
"EntityCommandExecutionException was unhandled by user code.
然後有人告訴我一下詳細信息的內部異常...還有我看到數據下:
"In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."
和下內部異常 - >消息:
"A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The handle is invalid.)"
Ť他編寫的Visual Studio認爲是有過錯的是:
Dim qpeople = (From p In dbContext2.PEOPLE _
Where p.PEOPLE_ID = ID _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
較大的代碼背景是:
Protected Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim semester As String = ddlwhSemester.SelectedValue
Dim year As String = txtwhYear.Text
Dim exists As String = "N"
Dim pcsemester As String = ddlSemester.SelectedItem.Text
Dim pcyear As String = ddlYear.SelectedItem.Text
Using dbContext As pbu_housingEntities = New pbu_housingEntities
' Get the list of residents in webHousing.
Dim qresidents = (From p In dbContext.Residents _
Where p.semester = semester _
Where p.year = year _
Select p.people_code_id)
Using dbContext2 As Campus6Entities = New Campus6Entities
' Get the list of students in PowerCampus.
Dim qstudents = (From p In dbContext2.RESIDENCies _
Join a In dbContext2.ACADEMICs _
On a.PEOPLE_CODE_ID Equals p.PEOPLE_CODE_ID _
Where p.ACADEMIC_TERM = pcsemester _
Where p.ACADEMIC_YEAR = pcyear _
Where a.ACADEMIC_TERM = pcsemester _
Where a.ACADEMIC_YEAR = pcyear _
Where a.PROGRAM = "UND" _
Where (a.CLASS_LEVEL = "FR" _
Or a.CLASS_LEVEL = "FRNR" _
Or a.CLASS_LEVEL = "FRST" _
Or a.CLASS_LEVEL = "SO" _
Or a.CLASS_LEVEL = "JR" _
Or a.CLASS_LEVEL = "SR" _
Or a.CLASS_LEVEL = "SR5" _
Or a.CLASS_LEVEL = "Tran") _
Select p.PEOPLE_ID).Distinct
For Each row In qstudents
exists = "N"
For Each res In qresidents
If row.ToString = res.ToString Then
exists = "Y"
End If
Next
If exists = "Y" Then
' Skip adding.
Else
' Add a row.
' Get the ID
Dim ID As String = row
' Get info from PowerCampus
Dim qpeople = (From p In dbContext2.PEOPLE _
Where p.PEOPLE_ID = ID _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
Dim people_code_id As String = qpeople.PEOPLE_CODE_ID
Dim qacademic = (From p In dbContext2.ACADEMICs _
Where p.PEOPLE_CODE_ID = people_code_id _
Where p.ACADEMIC_TERM = pcsemester _
Where p.ACADEMIC_YEAR = pcyear _
Order By p.CREATE_DATE Descending _
Select p.CLASS_LEVEL).FirstOrDefault
Dim qaddress = (From p In dbContext2.ADDRESSes _
Where p.PEOPLE_ORG_CODE_ID = people_code_id _
Where p.ADDRESS_TYPE = "Perm" _
Order By p.CREATE_DATE Descending _
Select p).FirstOrDefault
Dim qdemographics = (From p In dbContext2.DEMOGRAPHICS _
Where p.PEOPLE_CODE_ID = people_code_id _
Order By p.CREATE_DATE Descending _
Select p.GENDER).FirstOrDefault
' Create the new occupant.
Dim newres As New Resident
newres.people_code_id = ID
newres.person_name = qpeople.FIRST_NAME + " " + qpeople.MIDDLE_NAME + " " + qpeople.LAST_NAME
newres.first_name = qpeople.FIRST_NAME
newres.last_name = qpeople.LAST_NAME
newres.class_level = qacademic
newres.gender = qdemographics
newres.semester = semester
newres.year = year
newres.email = qaddress.EMAIL_ADDRESS
newres.create_date = Date.Now
dbContext.Residents.AddObject(newres)
dbContext.SaveChanges()
End If
Next
End Using
End Using
End Sub
Geez,我試過所有的東西和它的母親讓這個東西工作(完全重寫上面的代碼),修復很簡單。 – davemackey 2012-03-26 13:22:35
那麼,那工作...不幸的是,我後來意識到,我把它設置爲字符串的原因是B/C整數切斷了前導零 - 並且,不幸的是,其他數據庫使用前導零。 – davemackey 2012-03-26 18:28:13
在任何地方使用PEOPLE_CODE_ID解決前導零問題,因爲它總是以字母P開頭。 – bendodge 2018-03-07 17:26:45