How to specify the calculation for a new Typed List column

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 29-Oct-2007 23:04:45   

Hi, (Using Adapter Ver 2.00, VB, SQL 2K)

I'm extending a Typed List to add a calculated field, but don't actually know how to specify the calculation. This is what I've got:

    Partial Public Class BudgetDivisionsTypedList
        Protected Overrides Sub OnInitialized()
            'Create custom column
            Dim colFundTotal As New DataColumn("FundTotal", GetType(Integer), Nothing, MappingType.Element)
            Me.Columns.Add(colFundTotal)

            MyBase.OnInitialized()
        End Sub
End Class

How do I do the equivalent of: colFundTotal = V1Amount + V2Amount where V1Amount & V2Amount are existing columns within the Typed List.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2007 04:33:31   

Hi Markiemac,

You should define the expression that applies to that new column at _OnResultsetBuilt _method. You also have to include the column accessors. Here is an example: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8110&StartAtMessage=0&#44765

Hope helpful.

David Elizondo | LLBLGen Support Team
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 30-Oct-2007 14:25:54   

Hi Daelmo,

Thanks for your response. As my C# is poor I started working through the solution in the post you suggested. The Override for OnResultsetBuilt seems to be required for the scalar query and I couldn't see how that would help me, so I took another look at my code, and come up with the following:

Imports SD.LLBLGen.Pro.ORMSupportClasses
Namespace MIS.DAL.TypedListClasses
    Partial Public Class BudgetDivisionsTypedList
        Protected Overrides Sub OnInitialized()
            'Create custom column
            Dim colFundTotal As New DataColumn("FundTotal", GetType(Integer), "V1Amount + V2Amount", MappingType.Element)
            Me.Columns.Add(colFundTotal)
            MyBase.OnInitialized()
        End Sub
    End Class
End Namespace

This has given me what I want, but can you see a problem with it. If its ok, I'd love to know why I didn't need the OnResultsetBuilt override simple_smile

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Oct-2007 10:04:52   

This has given me what I want, but can you see a problem with it. If its ok, I'd love to know why I didn't need the OnResultsetBuilt override

Your code is ok, so if it works then don't ask why it does work smile

Let's get serious, the link posted above used OnResultsetBuilt to compute that column in the database, so the data returned from tha database has an extra field with values being computed already. While you have computed it at client side. i.e. you get the fields from the database without the extra computed field then you let your code do the rest.

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 01-Nov-2007 18:23:24   

Walaa, many thanks. I like pragmatism smile