I am using projection to a custom class and I am getting the following error: object of type 'system.int32' cannot be converted to type 'system.string'.
This is happening because the Key field in the business object is of type String and the related database field is named FileAttachmentId and is Int32.
It's trying to project the value of the integer frield in the database to the string field in the business object. I understand these are different data types. Is there anything I can do so that I can get this to work. They are different data types but a Int32 typically has no problem turning into a string value. In VB.NET work code it always converts automatically.
Is there something I can change so that I can allow this to work with the projection?
Try
Dim filter As New SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression()
filter.Add(New SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate(ORM.HelperClasses.FileAttachmentFields.PsrevisionId, SD.LLBLGen.Pro.ORMSupportClasses.ComparisonOperator.Equal, PSRevisionID))
Dim sort As New ORMSupportClasses.SortExpression
'sort.Add(New ORMSupportClasses.SortClause(ORM.HelperClasses.FileAttachmentFields.Title, ORMSupportClasses.SortOperator.Ascending))
Dim oFiles As New List(Of FileAttaching.FileAttachment)
Dim fields As New ORM.HelperClasses.ResultsetFields(8)
'TODO
fields(0) = ORM.HelperClasses.FileAttachmentFields.CreatedByDate
fields(1) = ORM.HelperClasses.FileAttachmentFields.CreatedById
fields(2) = ORM.HelperClasses.FileAttachmentFields.Description
fields(3) = ORM.HelperClasses.FileAttachmentFields.FileAttachmentId
fields(4) = ORM.HelperClasses.FileAttachmentFields.FileName
fields(5) = ORM.HelperClasses.FileAttachmentFields.InternalFileName
fields(6) = ORM.HelperClasses.FileAttachmentFields.Title
fields(7) = ORM.HelperClasses.FileAttachmentFields.FileAttachmentCategoryId
Dim projector As New ORMSupportClasses.DataProjectorToCustomClass(Of FileAttaching.FileAttachment)(oFiles)
' Define the projections of the fields. -these have to match case sensitive to the properties of the BO class
Dim valueProjectors As New List(Of ORMSupportClasses.IDataValueProjector)()
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("CreatedByDate", 0))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("CreatedByID", 1))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("Description", 2))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("Key", 3, GetType(System.Object)))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("FileName", 4))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("InternalFileName", 5))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("Title", 6))
valueProjectors.Add(New ORMSupportClasses.DataValueProjector("CategoryID", 7))
' perform the fetch combined with the projection.
Dim dao As New ORM.DaoClasses.TypedListDAO
dao.GetAsProjection(valueProjectors, projector, Nothing, fields, filter, Nothing, 0, sort, True)
Return oFiles
Catch exName As Exception
'Invoke policy that is responsible to handle the exception and recommend a rethrow.
Dim rethrow As Boolean = ExceptionPolicy.HandleException(exName, "Data")
If rethrow Then
Throw
End If
End Try