Projecting To Custom Class returns proper number of objects but all properties in them are empty objects

Posts   
 
    
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 20-Sep-2007 16:24:39   

Version 2.5 - August 27, 2007 .NET 2.0 - SelfServicing SQL Server 2000

I'm trying to project into a ListOf a custom class (code below). It returns the correct number of records (class objects in the list) but each property is either Nothing or 0. The code looks correct as per the example in the help documentation. I checked the debug output and verified that the SQL code it is using is correct and I have tried GetMultiAsDatatable and it returns the same amount of records into a datatable and the data is returned properly. Can someone help me out?

Imports SD.LLBLGen.Pro
Public Class WeldSpecs
    Public Function GetSpotWeldSpecs(ByVal AssyID As Integer) As System.Collections.Generic.List(Of Weld.Business.WeldSpec_Spot)
        '  Dim WeldSpecCol As New ORM.CollectionClasses.WeldSpec_SpotCollection

        Dim filter As New SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression()
        'Dim WeldSpecSpotEnt As New Weld.ORM.EntityClasses.WeldSpec_SpotEntity

        filter.Add(New SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate(ORM.HelperClasses.WeldSpec_SpotFields.AssyId, SD.LLBLGen.Pro.ORMSupportClasses.ComparisonOperator.Equal, AssyID))

        Dim sort As New ORMSupportClasses.SortExpression
        sort.Add(New ORMSupportClasses.SortClause(ORM.HelperClasses.WeldSpec_SpotFields.WeldGroup, ORMSupportClasses.SortOperator.Ascending))

        ' WeldSpecCol.GetMulti(filter, Long.MaxValue, sort)

        ' WeldSpecCol.GetMulti(filter, Integer.MaxValue, sort)


        'SpotDao.GetAsProjection()


        ' VB.NET .NET 2.0
        Dim oWeldSpecs_Spot As New List(Of Weld.Business.WeldSpec_Spot)()
        Dim fields As New ORM.HelperClasses.ResultsetFields(2)
        fields(0) = ORM.HelperClasses.WeldSpec_SpotFields.AssyId
        fields(1) = ORM.HelperClasses.WeldSpec_SpotFields.WeldSpec_SpotId
        'fields(2) = CustomerFields.CustomerId
        'fields(3) = CustomerFields.Country

        Dim projector As New ORMSupportClasses.DataProjectorToCustomClass(Of Weld.Business.WeldSpec_Spot)(oWeldSpecs_Spot)

        ' Define the projections of the fields. 
        Dim valueProjectors As New List(Of ORMSupportClasses.IDataValueProjector)()
        valueProjectors.Add(New ORMSupportClasses.DataValueProjector("AssyID", 0, GetType(Int32)))
        valueProjectors.Add(New ORMSupportClasses.DataValueProjector("WeldSpec_SpotId", 1, GetType(Int32)))
        'valueProjectors.Add(New DataValueProjector("CustomerID", 2, GetType(String)))
        'valueProjectors.Add(New DataValueProjector("Country", 3, GetType(String)))

        ' perform the fetch combined with the projection.
        Dim dao As New ORM.DaoClasses.WeldSpec_SpotDAO()

        'Dim SpotDao As New ORM.DaoClasses.WeldSpec_SpotDAO()
        dao.GetAsProjection(valueProjectors, projector, Nothing, fields, filter, Nothing, Integer.MaxValue, sort, True)



        Return oWeldSpecs_Spot



    End Function


End Class


Public Class WeldSpec_Spot
    Public [AssyId] As System.Int32
    Public WeldSpec_SpotID As Int32

    'Public [WeldGroup]() As System.String
    'Public [Quantity]() As Nullable(Of System.Int32)
    'Public [NuggetDiameter]() As Nullable(Of System.Decimal)
    'Public [UndersizeNuggetDiam]() As Nullable(Of System.Decimal)
    'Public [MaxIndent]() As System.String
    'Public [MinAcceptanceCriteria]() As System.String
    'Public [MaterialThickness_Governing]() As Nullable(Of System.Decimal)
    'Public [WeldSetupSize_Required]() As Nullable(Of System.Decimal)
    'Public [WeldSpec_Spot_WeldNo]() As Collections.Generic.List(Of WeldSpec_Spot_WeldNo)
End Class

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 16:46:20   

Please not that you are fetching a dynamic list from the database.

So you should use the following:

TypedListDAO dao = new TypedListDAO();
dao.GetAsProjection(valueProjectors, projector, Nothing, fields, filter, Nothing, Integer.MaxValue, sort, True)
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 20-Sep-2007 17:03:48   

Sorry, that was the first thing I tried and the results are the same.

Dam

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 17:13:17   

The property names in the custom class don't match those specified in the valueProjectors.

I think you need to use the following:

        Dim valueProjectors As New List(Of ORMSupportClasses.IDataValueProjector)()
        valueProjectors.Add(New ORMSupportClasses.DataValueProjector("AssyId", 0, GetType(Int32)))
        valueProjectors.Add(New ORMSupportClasses.DataValueProjector("WeldSpec_SpotID", 1, GetType(Int32)))

Take care of the "D" vs "d" in the field names. eg. "AssyId" vs "AssyID"

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 20-Sep-2007 17:18:15   

I just tried that, but I still get the same result.

rage

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 20-Sep-2007 19:46:34   

Still no luck. I modified the custom class to the following:

I've set a breakpoint and found that this code is not even running therefore it just adds empty objects to the List object, but doesn't even try to set the values. Does this help anyone to help me figure out how to fix this? I've been playing with this for many hours, and have followed all of the examples.

Public Class WeldSpec_Spot
    'Public [AssyId] As System.Int32


    Public Property AssyID() As Int32
        Get

        End Get
        Set(ByVal value As Int32)
            MsgBox(value)
        End Set
    End Property

    Public WeldSpec_SpotId As Int32

    'Public [WeldGroup]() As System.String
    'Public [Quantity]() As Nullable(Of System.Int32)
    'Public [NuggetDiameter]() As Nullable(Of System.Decimal)
    'Public [UndersizeNuggetDiam]() As Nullable(Of System.Decimal)
    'Public [MaxIndent]() As System.String
    'Public [MinAcceptanceCriteria]() As System.String
    'Public [MaterialThickness_Governing]() As Nullable(Of System.Decimal)
    'Public [WeldSetupSize_Required]() As Nullable(Of System.Decimal)
    'Public [WeldSpec_Spot_WeldNo]() As Collections.Generic.List(Of WeldSpec_Spot_WeldNo)
End Class

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Sep-2007 12:18:15   

You do need properties on your custom class, not public fields (your second custom class still has 1 public field). These properties have to have the name you specified for each projector, so if you add a DataValueProjector and specify "AssyID", the property also has to have that name. It's case sensitive. As you've changed the name to "AssyId" your property on your custom class also has to have that name, because the name in the datavalueprojector is the name of the DESTINATION property to store the value in. The value is read from the index you specify in the datavalueprojector, e.g. 0 and 1.

Frans Bouma | Lead developer LLBLGen Pro
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 21-Sep-2007 20:46:23   

Thank you sir!

This is working now, and your response really helped me understand and wrap my head around how the BO and projection work together to get the right results.

Dan

prabhu
User
Posts: 77
Joined: 20-Dec-2006
# Posted on: 12-Feb-2008 10:04:27   

Hi Otis,

Can you please explain why we should not use public fields instead of properties in custom classes. We dont want the validation to be done at the custom classes. Using custom classes as an DTO in our project.

Regards

Prabhu

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Feb-2008 12:38:02   

Public fields aren't usable in databinding, not usable in projections (the projector uses property descriptors, not field descriptors) and in general not a good idea, as they expose inner class elements. A class should encapsulate data.

Frans Bouma | Lead developer LLBLGen Pro