Log in


   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> Type Conversion Error With Projection

Pages: 1
Bugs & Issues
Type Conversion Error With Projection

  Print all messages in this thread  
Poster Message


Joined on:
20-Sep-2007 16:09:06
41 posts
# Posted on: 29-Apr-2009 18:57:39.  
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?

            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(Cool
            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
            End If
        End Try
Support Team


Joined on:
21-Aug-2005 16:03:48
14626 posts
# Posted on: 30-Apr-2009 10:27:59.  
Either change your business object to have a matching type for that field.

Or if business really requires a string type, the maybe you need to use a TypeConverter to convert from the database int type to a string type for the generated entity and for the projection as well.

Pages: 1  

Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.