Overriding Fill() method on TypedList from Partial Class

Posts   
 
    
jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 26-Oct-2007 21:49:00   

Hi,

I am trying to override the fill method of a Typed List via a partial class.

My declaration looks like this:



        Public Overrides Function Fill(ByVal maxNumberOfItemsToReturn As Long, ByVal sortClauses As ISortExpression, ByVal allowDuplicates As Boolean, ByVal selectFilter As IPredicate, ByVal transactionToUse As ITransaction, ByVal groupByClause As IGroupByCollection, ByVal pageNumber As Integer, ByVal pageSize As Integer) As Boolean

        End Function


Unfortunately Visual Studio says I can't do this because the method has "multiple definitions with identical signatures". I originally tried it this way based on this post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6425&HighLight=1.

My end goal is to have a new column on the typed list named StandardCode that varies based on other values in the row. I know I could use an expression column but I think the logic for my formatting is too complicated as it's more like a case statement.

Pseude code for deriving new columns value:


If field1 = 1 then
newField = field2 + '.(' + field3 + '.)'
else
newField = field2 + '(' + field3 + '.' + field4 + ')
end if

Please help. Thanks!

.jelling

Posts: 254
Joined: 16-Nov-2006
# Posted on: 27-Oct-2007 21:36:28   

I wouldn't recommend you override the Fill method to achieve your goal here

Review this thread which covers this specific scenario. In your custom column you can simply add any formatting requirements based on the values of other fields.

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 27-Oct-2007 21:40:13   

MattAdamson wrote:

I wouldn't recommend you override the Fill method to achieve your goal here

Review this thread which covers this specific scenario. In your custom column you can simply add any formatting requirements based on the values of other fields.

Hi Matt,

All of the examples I have seen of using the expression column - I assume that's what you're referring to - are pretty simple like "fields + field2". Can I use the sort of logic I displayed in my pseudo-code in the expression column?

Thanks,

.jelling

Posts: 254
Joined: 16-Nov-2006
# Posted on: 27-Oct-2007 22:02:05   

Yes absolutely , what ever logic you can create in code simple_smile

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 27-Oct-2007 23:03:49   

MattAdamson wrote:

Yes absolutely , what ever logic you can create in code simple_smile

Great. I'll look into that. One more thing: do you know what's up with not being able to override an overrideable method?

.jelling

Posts: 254
Joined: 16-Nov-2006
# Posted on: 27-Oct-2007 23:05:34   

I'm not that familiar with VB.NET unfortunately however it would certainly help if you posted the full compiler error message here.

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 27-Oct-2007 23:40:03   

MattAdamson wrote:

Yes absolutely , what ever logic you can create in code simple_smile

Sorry to be so dense, but can you give me an example of how to create an expression to implement my pseudo-code in the original post? All I see after reviewing the docs is a ScalarQueryExpression which doesn't seem to fit the bill.

Here's what I've got so far:


        Protected Overrides Sub OnInitialized()
            'create our custom columns

            Dim standardCodeColumn As New DataColumn("StandardCode", GetType(String), Nothing, MappingType.Element)
            Me.Columns.Add(standardCodeColumn)

            MyBase.OnInitialized()
        End Sub

        Protected Overrides Sub OnResultsetBuilt(ByVal fields As SD.LLBLGen.Pro.ORMSupportClasses.IEntityFields)
            'fill our custom columns

            Dim sStandardCode As String
            sStandardCode = "foo"

            Dim fieldStandardCode As New EntityField("StandardCode", ?What do I do here?)


            fields.Expand(1)
            fields.DefineField(fieldStandardCode, fields.count)
            
            MyBase.OnResultsetBuilt(fields)

        End Sub
    End Class

    'extend the row class to allow access to our custom columns
    Partial Public Class StandardRow

        Public ReadOnly Property StandardCode() As String
            Get
                Return Me._parent.Columns("StandardCode").ToString
            End Get
        End Property
    End Class

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 28-Oct-2007 01:56:46   

Okay, here's my latest attempt. I feel like I'm getting close but when I run this code the CASE statement doesn't seem to work as a column expression. Any suggestions?

It is very important for my team's adoption of LLBL that we can define computed columns outside of SQL views.



    Partial Public Class StandardTypedList

        Protected Overrides Sub OnInitialized()
            'create our custom columns

            Dim standardCodeColumn As New DataColumn("StandardCode", GetType(String), Nothing, MappingType.Element)
            

            'using the alias as defined in the typed list, verified column exists via debug
            'neither of these CASE statements work but they work in SQL
            'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
            standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"


            Me.Columns.Add(standardCodeColumn)

            MyBase.OnInitialized()
        End Sub

    End Class


    'extend the row class to allow access to our custom columns
    Partial Public Class StandardRow

        Public ReadOnly Property StandardCode() As String
            Get
                Return Me._parent.Columns("StandardCode").ToString
            End Get
        End Property
    End Class

The error I get is this:


Syntax error: Missing operand after 'WHEN' operator. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand after 'WHEN' operator.

Source Error: 


Line 14:             'using the alias as defined in the typed list
Line 15:             'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
Line 16:             standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
Line 17: 
Line 18: 


Source File: C:\Inetpub\wwwroot\VSuite\VSurveyDAL\BLL\StandardTypedList.vb  Line: 16 

Stack Trace: 


[SyntaxErrorException: Syntax error: Missing operand after 'WHEN' operator.]
   System.Data.ExpressionParser.Parse() +1240829
   System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +123
   System.Data.DataColumn.set_Expression(String value) +101
   VSurvey.DAL.TypedListClasses.StandardTypedList.OnInitialized() in C:\Inetpub\wwwroot\VSuite\VSurveyDAL\BLL\StandardTypedList.vb:16
   VSurvey.DAL.TypedListClasses.StandardTypedList.InitClass(Boolean obeyWeakRelations) in C:\Inetpub\wwwroot\VSuite\VSurveyDAL\TypedListClasses\StandardTypedList.vb:473
   VSurvey.DAL.TypedListClasses.StandardTypedList..ctor() in C:\Inetpub\wwwroot\VSuite\VSurveyDAL\TypedListClasses\StandardTypedList.vb:93
   epchanges_editep.populateStandards() in C:\Inetpub\wwwroot\VSuite\VStandardAdmin\epchanges\editep.aspx.vb:184
   epchanges_editep.ddlFutureChangeType_SelectedIndexChanged(Object sender, EventArgs e) in C:\Inetpub\wwwroot\VSuite\VStandardAdmin\epchanges\editep.aspx.vb:374
   System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +105
   System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +134
   System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +7
   System.Web.UI.Page.RaiseChangedEvents() +137
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +477

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Oct-2007 04:06:05   

Example about "How to Add a new Custom Column in Typed List": http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8110&StartAtMessage=0&#44765

Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand after 'WHEN' operator.

Source Error:

Line 14: 'using the alias as defined in the typed list Line 15: 'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END" Line 16: standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END" Line 17: Line 18:

standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1

The CASE statement is in incorrect format.. Shouldn't be like this?:

CASE input_expression 
    WHEN when_expression THEN result_expression 
        [ ...n ] 
    [ 
        ELSE else_result_expression 
    ] 
END 

BTW, What LLBLGen version are you using?

David Elizondo | LLBLGen Support Team
jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 29-Oct-2007 15:32:30   

daelmo wrote:

Example about "How to Add a new Custom Column in Typed List": http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8110&StartAtMessage=0&#44765

Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand after 'WHEN' operator.

Source Error:

Line 14: 'using the alias as defined in the typed list Line 15: 'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END" Line 16: standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END" Line 17: Line 18:

standardCodeColumn.Expression = "CASE WHEN StandardsBodyID = 1

The CASE statement is in incorrect format.. Shouldn't be like this?:

CASE input_expression 
    WHEN when_expression THEN result_expression 
        [ ...n ] 
    [ 
        ELSE else_result_expression 
    ] 
END 

BTW, What LLBLGen version are you using?

You mean like line 15? simple_smile Seriously, I spent a ton of time on this and I think the underlying problem is that the data expression property (by MS) doesn't support case statements. Nested IIF()'s is probably the best option but what I've done is just add a custom property to the entity and taken the hit on the multiple queries.

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 29-Oct-2007 20:44:36   

daelmo wrote:

Example about "How to Add a new Custom Column in Typed List": ...

BTW, What LLBLGen version are you using?

I'm using LLBLGen 2.5. Do you think that is affecting things?

This also didn't work:

        standardCodeColumn.Expression = "CASE StandardsBodyID WHEN standardsBody = 1 THEN 'JCAHO' ELSE 'Non-JCAHO' END"
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Oct-2007 11:44:36   

The original problem was:

I am trying to override the fill method of a Typed List via a partial class.

My declaration looks like this:

    Public Overrides Function Fill(ByVal maxNumberOfItemsToReturn As Long, ByVal sortClauses As ISortExpression, ByVal allowDuplicates As Boolean, ByVal selectFilter As IPredicate, ByVal transactionToUse As ITransaction, ByVal groupByClause As IGroupByCollection, ByVal pageNumber As Integer, ByVal pageSize As Integer) As Boolean

    End Function

Unfortunately Visual Studio says I can't do this because the method has "multiple definitions with identical signatures".

I think you shoulod inherit from the TypedList in hand, to override any of its virtual Fill() methods. Note that the Fill methods are implemented in the generated TypedList class not in a parent class.

Great. I'll look into that. One more thing: do you know what's up with not being able to override an overrideable method?

Same issue I think, you are trying to override it in the same class (partial). When you should override it in a subClass.

jelling
User
Posts: 22
Joined: 26-Oct-2007
# Posted on: 30-Oct-2007 16:32:39   

Walaa wrote:

The original problem was:

I think you shoulod inherit from the TypedList in hand, to override any of its virtual Fill() methods. Note that the Fill methods are implemented in the generated TypedList class not in a parent class.

Great. I'll look into that. One more thing: do you know what's up with not being able to override an overrideable method?

Same issue I think, you are trying to override it in the same class (partial). When you should override it in a subClass.

That makes a lot more sense. I'll give that a try. Right now I'm having to use typed views with the business logic (i.e. a case statement) in the view. That kind of defeats the philosophical purpose of using LLBLGen which was to put all BL in the BLL.

Thanks.