'Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.'

  • Thread starter Thread starter Frosty8467
  • Start date Start date
F

Frosty8467

Guest
I am new to MVC and I am trying to create an edit form that allows me to edit data in an entity and it's child entity at the same time.

Below are my two Models

Public Class tblInspection
<StringLength(6)>
Public Property Inspection_Mooring_Code As String
'<DataType(DataType.DateTime)>
<DisplayFormat(DataFormatString:="{0:dd-MM-yyyy}", ApplyFormatInEditMode:=True)>
Public Property Inspection_Date As DateTime?
<DisplayFormat(NullDisplayText:="")>
Public Property Inspection_Passed As Boolean?
<StringLength(5000)>
Public Property Inspection_Comments As String
<Key>
Public Property Inspection_ID As Integer
<StringLength(2)>
Public Property Inspection_Mooring_zone As String
<DisplayFormat(NullDisplayText:="")>
Public Property Inspection_Mooring_Cycle As System.Int32?
<StringLength(2)>
Public Property InspectionMooringInspectorCode As String
<StringLength(50)>
Public Property InspectionContractor As String
<StringLength(255)>
Public Property InspectionClient As String
<StringLength(255)>
Public Property InspectionAddress As String
<StringLength(100)>
Public Property Inspectionemail As String
<DisplayFormat(NullDisplayText:="")>
Public Property InspectionConsentForm As System.Int16
<StringLength(150)>
Public Property InspectionLicencedHolder As String
<StringLength(100)>
Public Property InspectionPhone As String
<StringLength(100)>
Public Property InspectionMobile As String
<StringLength(20)>
Public Property InspectionInspectionRegime As String
<StringLength(4)>
Public Property InspectionMooring_Area As String
<StringLength(20)>
Public Property InspectionBuoy_Colour As String
<StringLength(50)>
Public Property InspectionVessel_Name As String
<DisplayFormat(NullDisplayText:="")>
Public Property InspectionVessel_Length As Double?
<StringLength(5)>
Public Property InspectionWeight_Tag As String
<StringLength(7)>
Public Property InspectionLatitude As String
<StringLength(8)>
Public Property InspectionLongitude As String
<StringLength(6)>
Public Property InspectionNotes As String
Public Property InspectionMooring_Condition_Summary As String
<DisplayFormat(NullDisplayText:="")>
Public Property InspectionDateEntered As Date?
<StringLength(20)>
Public Property InspectionStatus As String

Public Property MooringInspectionDetails() As List(Of MooringInspectionDetail)

End Class

Public Class MooringInspectionDetail
<Key>
Public Property MooringInspectionDetailID As Integer
<ForeignKey("ParentInspection")>
Public Property Inspection_ID As Integer
<StringLength(50)>
Public Property MooringInspectionDetailItem As String
<StringLength(50)>
Public Property MooringInspectionDetailSize As String
<StringLength(50)>
Public Property MooringInspectionDetailLength As String
<StringLength(10)>
Public Property MooringInspectionDetailResult As String
<StringLength(10)>
Public Property MooringInspectionDetailNew As String
Public Property ParentInspection() As tblInspection
End Class


And here is my Edit action in my tblinspectionController

Function Edit(ByVal id As Integer?) As ActionResult
If IsNothing(id) Then
Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
End If
Dim tblInspection As tblInspection = db.tblInspections.Include(Function(i) i.MooringInspectionDetails).Where(Function(c) id.Equals(c.Inspection_ID)).Single
If IsNothing(tblInspection) Then
Return HttpNotFound()
End If

Return View(tblInspection)
End Function


But when the code runs and it gets to the include statement it fails with the above error.


What have I done wrong


Thanks in advance


Frosty

Continue reading...
 
Back
Top