我正在准备显示我的数据库中包含的比赛列表,但每次出现此错误时都会让我感到震惊:
序列化类型为“WhereSelectListIterator
2[jTableSampleDatabaseLayer.Hik.JTable.Models.Concour,VB$AnonymousType_2
8[System.String,System.Nullable1[System.Int32],System.Nullable
1[System.Int32],System.DateTime,System.Int32,System.Int32,System.String,System.Int32]]的对象时检测到循环引用' on type 'System.Collections.Generic.IEnumerable
1[jTableSampleDatabaseLayer.Hik.JTable.Models.Concour]``'。
这是我在 vb 中的代码:
Dim x As jTableSampleDatabaseLayer.totofootEntities = _
New jTableSampleDatabaseLayer.totofootEntities
Dim dataSource = New MemoryDataSource()
Dim liste As List(Of Concour) = x.Concours.ToList()
dataSource.Concours.AddRange(liste)
''ajout
Try
Dim concours = dataSource.Concours
Return Json(New With { _
Key .Result = "OK", _
Key .Records = concours _
}, JsonRequestBehavior.AllowGet)
Catch ex As Exception
Return Json(New With { _
Key .Result = "ERROR", _
Key .Message = ex.Message _
}, JsonRequestBehavior.AllowGet)
End Try
我怎样才能避免这个错误?
我试图更改代码以避免此错误
现在我不再收到错误,但我得到的结果是所有属性都等于 null 并且在我的数据库中注册的数量相同
{"结果":"OK","记录":[{"numero_concours":null,"numero_etape":0,"numero_type":null,"numero_nature":null,"titre_concours":null,"date_de_sortie":" /Date(-62135596800000)/","nbre_matchs":0,"nbre_rangs":0,"Etape":null,"Nature":null,"Type":null,"Primes":[],"Rangs": [],"Recettes":[],"Rencontres":[]},{"numero_concours":null,"numero_etape":0,"numero_type":null,"numero_nature":null,"titre_concours":null," date_de_sortie":"/Date(-62135596800000)/","nbre_matchs":0,"nbre_rangs":0,"Etape":null,"Nature":null,"Type":null,"Primes":[], "Rangs":[],"Recettes":[],"Rencontres":[]}]}``'。
新代码:
Dim x As jTableSampleDatabaseLayer.totofootEntities = New jTableSampleDatabaseLayer.totofootEntities
Dim dataSource = New MemoryDataSource()
Dim liste As List(Of Concour) = x.Concours.ToList()
dataSource.Concours.AddRange(liste.Select(Function(p) New Concour))
''ajout
Try
Dim concours = dataSource.Concours
Return Json(New With {Key .Result = "OK", Key .Records = concours}, JsonRequestBehavior.AllowGet)
Catch ex As Exception
Return Json(New With {Key .Result = "ERROR", Key .Message = ex.Message}, JsonRequestBehavior.AllowGet)
End Try